import { useNavigate } from '@tanstack/react-router'
import { Card } from '@/components/ui/card'
import { Button } from '@/components/ui/button'
import { formatRelativeTime } from '@/lib/utils'
import type { PendingReviewInitiativeItem, PendingReviewPhaseItem } from './types'

interface Props {
  initiatives: PendingReviewInitiativeItem[]
  phases: PendingReviewPhaseItem[]
}

export function HQNeedsReviewSection({ initiatives, phases }: Props) {
  const navigate = useNavigate()

  return (
    <div className="space-y-3">
      <h2 className="text-sm font-medium text-muted-foreground uppercase tracking-wide">
        Needs Review
      </h2>
      <div className="space-y-2">
        {initiatives.map((item) => (
          <Card key={item.initiativeId} className="p-4 flex items-center justify-between gap-4">
            <div className="min-w-0 flex-1">
              <p className="font-semibold text-sm">{item.initiativeName}</p>
              <p className="text-sm text-muted-foreground">Content ready for review</p>
              <p className="text-xs text-muted-foreground">{formatRelativeTime(item.since)}</p>
            </div>
            <Button
              variant="outline"
              size="sm"
              onClick={() =>
                navigate({
                  to: '/initiatives/$id',
                  params: { id: item.initiativeId },
                  search: { tab: 'review' },
                })
              }
            >
              Review
            </Button>
          </Card>
        ))}
        {phases.map((item) => (
          <Card key={item.phaseId} className="p-4 flex items-center justify-between gap-4">
            <div className="min-w-0 flex-1">
              <p className="font-semibold text-sm">{item.initiativeName} › {item.phaseName}</p>
              <p className="text-sm text-muted-foreground">Phase execution complete — review diff</p>
              <p className="text-xs text-muted-foreground">{formatRelativeTime(item.since)}</p>
            </div>
            <Button
              variant="outline"
              size="sm"
              onClick={() =>
                navigate({
                  to: '/initiatives/$id',
                  params: { id: item.initiativeId },
                  search: { tab: 'review' },
                })
              }
            >
              Review Diff
            </Button>
          </Card>
        ))}
      </div>
    </div>
  )
}
