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 { StatusDot } from '@/components/StatusDot'
import { formatRelativeTime } from '@/lib/utils'
import type { ResolvingConflictsItem } from './types'

interface Props {
  items: ResolvingConflictsItem[]
}

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

  return (
    <div className="space-y-3">
      <h2 className="text-sm font-medium text-muted-foreground uppercase tracking-wide">
        Resolving Conflicts
      </h2>
      <div className="space-y-2">
        {items.map((item) => (
          <Card key={item.agentId} className="p-4 flex items-center justify-between gap-4">
            <div className="min-w-0 flex-1">
              <div className="flex items-center gap-2 text-sm">
                <StatusDot status="resolving_conflict" variant="urgent" size="sm" pulse />
                <span className="font-semibold">{item.initiativeName}</span>
                <Badge variant="urgent" size="xs">{item.agentStatus === 'waiting_for_input' ? 'Needs Input' : 'Running'}</Badge>
              </div>
              <p className="text-xs text-muted-foreground mt-1">
                {item.agentName} · started {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>
  )
}
