'use client'

import { RoundStatsIntake } from '@/components/dashboard/round-stats-intake'
import { RoundStatsFiltering } from '@/components/dashboard/round-stats-filtering'
import { RoundStatsEvaluation } from '@/components/dashboard/round-stats-evaluation'
import { RoundStatsSubmission } from '@/components/dashboard/round-stats-submission'
import { RoundStatsMentoring } from '@/components/dashboard/round-stats-mentoring'
import { RoundStatsLiveFinal } from '@/components/dashboard/round-stats-live-final'
import { RoundStatsDeliberation } from '@/components/dashboard/round-stats-deliberation'
import { RoundStatsSummary } from '@/components/dashboard/round-stats-summary'

type PipelineRound = {
  id: string
  name: string
  roundType: string
  status: string
  projectStates: {
    PENDING: number
    IN_PROGRESS: number
    PASSED: number
    REJECTED: number
    COMPLETED: number
    WITHDRAWN: number
    total: number
  }
  assignmentCount: number
  evalSubmitted: number
  evalDraft: number
  evalTotal: number
  filteringPassed: number
  filteringRejected: number
  filteringFlagged: number
  filteringTotal: number
  liveSessionStatus: string | null
  deliberationCount: number
  windowOpenAt: Date | null
  windowCloseAt: Date | null
  sortOrder: number
  slug: string
}

type RoundStatsProps = {
  activeRound: PipelineRound | null
  allActiveRounds?: PipelineRound[]
  projectCount: number
  newProjectsThisWeek: number
  totalJurors: number
  activeJurors: number
  totalAssignments: number
  evaluationStats: Array<{ status: string; _count: number }>
  actionsCount: number
  nextDraftRound?: { name: string; roundType: string } | null
}

export function RoundStats({
  activeRound,
  projectCount,
  newProjectsThisWeek,
  totalJurors,
  activeJurors,
  totalAssignments,
  evaluationStats,
  actionsCount,
  nextDraftRound,
}: RoundStatsProps) {
  if (!activeRound) {
    return (
      <RoundStatsSummary
        projectCount={projectCount}
        newProjectsThisWeek={newProjectsThisWeek}
        totalJurors={totalJurors}
        activeJurors={activeJurors}
        totalAssignments={totalAssignments}
        evaluationStats={evaluationStats}
        actionsCount={actionsCount}
        nextDraftRound={nextDraftRound}
      />
    )
  }

  switch (activeRound.roundType) {
    case 'INTAKE':
      return (
        <RoundStatsIntake
          round={activeRound}
          newProjectsThisWeek={newProjectsThisWeek}
        />
      )
    case 'FILTERING':
      return (
        <RoundStatsFiltering round={activeRound} />
      )
    case 'EVALUATION':
      return (
        <RoundStatsEvaluation
          round={activeRound}
          activeJurors={activeJurors}
        />
      )
    case 'SUBMISSION':
      return (
        <RoundStatsSubmission round={activeRound} />
      )
    case 'MENTORING':
      return (
        <RoundStatsMentoring round={activeRound} />
      )
    case 'LIVE_FINAL':
      return (
        <RoundStatsLiveFinal round={activeRound} />
      )
    case 'DELIBERATION':
      return (
        <RoundStatsDeliberation round={activeRound} />
      )
    default:
      return (
        <RoundStatsSummary
          projectCount={projectCount}
          newProjectsThisWeek={newProjectsThisWeek}
          totalJurors={totalJurors}
          activeJurors={activeJurors}
          totalAssignments={totalAssignments}
          evaluationStats={evaluationStats}
          actionsCount={actionsCount}
          nextDraftRound={nextDraftRound}
        />
      )
  }
}
