'use client'; import { useState } from 'react'; import Link from 'next/link'; import { useParams } from 'next/navigation'; import { useQuery } from '@tanstack/react-query'; import { AlertTriangle, ArrowRight } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { EmptyState } from '@/components/ui/empty-state'; import { StatusPill, type StatusPillStatus } from '@/components/ui/status-pill'; import { apiFetch } from '@/lib/api/client'; import { CatchUpWizard } from '@/components/berths/catch-up-wizard'; interface ReconcileRow { id: string; mooringNumber: string; area: string | null; status: string; statusLastChangedBy: string | null; statusLastChangedReason: string | null; statusLastModified: string | null; } const STATUS_LABELS: Record = { available: 'Available', under_offer: 'Under Offer', sold: 'Sold', }; const STATUS_PILL: Record = { available: 'available', under_offer: 'under_offer', sold: 'sold', }; function relativeAge(iso: string | null): string { if (!iso) return '—'; const days = Math.floor((Date.now() - new Date(iso).getTime()) / 86_400_000); if (days <= 0) return 'today'; if (days === 1) return 'yesterday'; if (days < 30) return `${days}d ago`; if (days < 365) return `${Math.floor(days / 30)}mo ago`; return `${Math.floor(days / 365)}y ago`; } export function ReconcileQueue() { const params = useParams<{ portSlug: string }>(); const portSlug = params?.portSlug ?? ''; const [wizardBerthId, setWizardBerthId] = useState(null); const { data, isLoading } = useQuery<{ data: ReconcileRow[]; total: number }>({ queryKey: ['berths', 'reconcile-queue'], queryFn: () => apiFetch('/api/v1/berths/reconcile-queue'), }); if (isLoading) { return (
    {[0, 1, 2].map((i) => (
  • ))}
); } const rows = data?.data ?? []; if (rows.length === 0) { return ( } title="Nothing to reconcile" body="Every berth that's been flipped manually has a backing interest. Manual status changes will show up here when there's no deal to explain them." /> ); } return ( <>
    {rows.map((r) => (
  • {r.mooringNumber} {r.area ? {r.area} : null} {r.statusLastChangedReason ? (

    {r.statusLastChangedReason}

    ) : null}
    {STATUS_LABELS[r.status] ?? r.status} {relativeAge(r.statusLastModified)}
  • ))}
!o && setWizardBerthId(null)} /> ); }