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 { InboxSuggestionDTO } from '../../api/inbox'
import type { AISessionDTO, CreateAISessionInput } from '../../api/ai'

export function ProjectChannelPage({
  activeChannel,
  activeWorkspace,
  activeTaskID,
  onSelectItem,
  onOpenTask,
  onCloseTask,
  onCreateTask,
  onUploadSource,
  onCreateCronPlan,
  onCreateProjectTag,
  onUpdateTask,
  onAnalyzeInbox,
  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) => void
  onUpdateTask: (update: ProjectTaskUpdate) => void
  onAnalyzeInbox: (inboxId: string) => Promise<InboxSuggestionDTO[]>
  onConfirmInbox: (inboxId: string, suggestionIds: string[]) => Promise<InboxConfirmationOutcome>
  onListAISessions: (projectId: string, signal?: AbortSignal) => Promise<AISessionDTO[]>
  onCreateAISession: (projectId: string, input: CreateAISessionInput, signal?: AbortSignal) => Promise<AISessionDTO>
}) {
  switch (activeChannel) {
    case 'inbox':
      return <ProjectInbox key={activeWorkspace.project.id} activeWorkspace={activeWorkspace} 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} />
  }
}
