import { Badge } from '@/components/ui/badge'
import { STATUS_LABELS } from '@/lib/domain/status'
import type { TripStatus } from '@/types/db'

const styles: Record<TripStatus, string> = {
  draft: 'bg-neutral-100 text-neutral-600 border-neutral-200',
  waiting_for_permits: 'bg-amber-50 text-amber-700 border-amber-200',
  active: 'bg-green-50 text-green-700 border-green-200',
  completed: 'bg-neutral-100 text-neutral-600 border-neutral-200',
  cancelled: 'bg-red-50 text-red-600 border-red-200',
}

/**
 * Trip status chip. On trips with a permit-handling policy, the waiting
 * status names who the trip is waiting ON (order-intake doc §7): the carrier
 * ("Waiting on Carrier Permits") or Synchron ("Synchron Permits Processing").
 */
export function StatusBadge({
  status,
  policy,
}: {
  status: TripStatus
  policy?: 'synchron_required' | 'upload_allowed' | null
}) {
  const label =
    status === 'waiting_for_permits' && policy
      ? policy === 'synchron_required'
        ? 'Synchron Permits Processing'
        : 'Waiting on Carrier Permits'
      : STATUS_LABELS[status]
  return (
    <Badge variant="outline" className={styles[status]}>
      {label}
    </Badge>
  )
}
