import { ProjectAi } from './project-ai'
import { ProjectCron } from './project-cron'
import { ProjectInbox } from './project-inbox'
import { ProjectNewChannel } from './project-new-channel'
import { ProjectNotes } from './project-notes'
import { ProjectOverview } from './project-overview'
import type { ProjectTaskUpdate } from './project-task-edit-modal'
import { ProjectTasks } from './project-tasks'
import type { ChannelKey, InboxConfirmationOutcome, ProjectWorkspace } from './project-types'
import type { CaptureInboxInput, InboxSuggestionDTO } from '../../api/inbox'
import type { AISessionDTO, CreateAISessionInput } from '../../api/ai'
import { Card, Empty, Typography } from '@arco-design/web-react'

const { Text } = Typography

export function ProjectChannelPage({
  activeChannel,
  activeWorkspace,
  activeTaskID,
  onSelectItem,
  onOpenTask,
  onCloseTask,
  onCreateTask,
  onUploadSource,
  onCreateCronPlan,
  onCreateProjectTag,
  onUpdateTask,
  onAnalyzeInbox,
  onCaptureInbox,
  onConfirmInbox,
  onListAISessions,
  onCreateAISession,
}: {
  activeChannel: ChannelKey
  activeWorkspace: ProjectWorkspace
  activeTaskID: string | null
  onSelectItem: (title: string) => void
  onOpenTask: (taskID: string) => void
  onCloseTask: () => void
  onCreateTask: () => void
  onUploadSource: () => void
  onCreateCronPlan: () => void
  onCreateProjectTag: (name: string) => Promise<void>
  onUpdateTask: (update: ProjectTaskUpdate) => Promise<void>
  onAnalyzeInbox: (inboxId: string) => Promise<InboxSuggestionDTO[]>
  onCaptureInbox: (projectId: string, input: CaptureInboxInput) => Promise<string>
  onConfirmInbox: (inboxId: string, suggestionIds: string[]) => Promise<InboxConfirmationOutcome>
  onListAISessions: (projectId: string, signal?: AbortSignal) => Promise<AISessionDTO[]>
  onCreateAISession: (projectId: string, input: CreateAISessionInput, signal?: AbortSignal) => Promise<AISessionDTO>
}) {
  if (activeChannel.startsWith('custom:')) {
    return (
      <div className="project-channel-page project-unavailable-page overview-page">
        <Card className="queue-section" bordered>
          <Empty description="自定义链接频道暂未开放" />
          <Text type="secondary">MVP 当前只展示频道配置，不会跳转或模拟外部功能。</Text>
        </Card>
      </div>
    )
  }

  switch (activeChannel) {
    case 'inbox':
      return <ProjectInbox key={activeWorkspace.project.id} activeWorkspace={activeWorkspace} onCapture={onCaptureInbox} onAnalyze={onAnalyzeInbox} onConfirm={onConfirmInbox} />
    case 'tasks':
      return <ProjectTasks activeWorkspace={activeWorkspace} activeTaskID={activeTaskID} onOpenTask={onOpenTask} onCloseTask={onCloseTask} onSelectItem={onSelectItem} onCreateTask={onCreateTask} onCreateProjectTag={onCreateProjectTag} onUpdateTask={onUpdateTask} />
    case 'ai':
      return <ProjectAi key={activeWorkspace.project.id} activeWorkspace={activeWorkspace} onSelectItem={onSelectItem} onListSessions={onListAISessions} onCreateSession={onCreateAISession} />
    case 'notes':
      return <ProjectNotes activeWorkspace={activeWorkspace} onSelectItem={onSelectItem} onUploadSource={onUploadSource} />
    case 'cron':
      return <ProjectCron activeWorkspace={activeWorkspace} onSelectItem={onSelectItem} onCreateCronPlan={onCreateCronPlan} />
    case 'new-channel':
      return <ProjectNewChannel activeWorkspace={activeWorkspace} />
    case 'overview':
    default:
      return <ProjectOverview activeWorkspace={activeWorkspace} onSelectItem={onSelectItem} onUpdateTask={onUpdateTask} />
  }
}
