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

interface Props {
  items: BlockedPhaseItem[]
}

export function HQBlockedSection({ items }: Props) {
  const navigate = useNavigate()

  return (
    <div className="space-y-3">
      <h2 className="text-sm font-medium text-muted-foreground uppercase tracking-wide">
        Blocked
      </h2>
      <div className="space-y-2">
        {items.map((item) => (
          <Card key={item.phaseId} className="p-4 flex items-center justify-between gap-4">
            <div className="min-w-0 flex-1">
              <div className="flex items-center gap-1 font-semibold text-sm">
                <span>{item.initiativeName} › {item.phaseName}</span>
                <Badge variant="destructive" className="ml-2">Blocked</Badge>
              </div>
              {item.lastMessage && (
                <p className="text-xs text-muted-foreground mt-1">{item.lastMessage}</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: 'execution' },
                })
              }
            >
              View
            </Button>
          </Card>
        ))}
      </div>
    </div>
  )
}
