'use client'; import Link from 'next/link'; import { useQuery } from '@tanstack/react-query'; import { Loader2 } from 'lucide-react'; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from '@/components/ui/table'; import { EmptyState } from '@/components/shared/empty-state'; import { apiFetch } from '@/lib/api/client'; interface OwnedYachtRow { id: string; name: string; hullNumber: string | null; lengthFt: string | null; widthFt: string | null; lengthM: string | null; widthM: string | null; status: string; } interface YachtListResponse { data: OwnedYachtRow[]; } interface CompanyOwnedYachtsTabProps { companyId: string; portSlug: string; } const STATUS_COLORS: Record = { active: 'bg-green-100 text-green-800 border-green-300', retired: 'bg-gray-100 text-gray-800 border-gray-300', sold_away: 'bg-amber-100 text-amber-800 border-amber-300', }; const STATUS_LABELS: Record = { active: 'Active', retired: 'Retired', sold_away: 'Sold Away', }; function formatDimensions(y: OwnedYachtRow): string | null { if (y.lengthFt || y.widthFt) { const length = y.lengthFt ?? '—'; const width = y.widthFt ?? '—'; return `${length} × ${width} ft`; } if (y.lengthM || y.widthM) { const length = y.lengthM ?? '—'; const width = y.widthM ?? '—'; return `${length} × ${width} m`; } return null; } export function CompanyOwnedYachtsTab({ companyId, portSlug }: CompanyOwnedYachtsTabProps) { const { data, isLoading } = useQuery({ queryKey: ['companies', companyId, 'owned-yachts'], queryFn: async () => { const params = new URLSearchParams({ ownerType: 'company', ownerId: companyId, page: '1', limit: '50', includeArchived: 'false', order: 'desc', }); const res = await apiFetch(`/api/v1/yachts?${params.toString()}`); return res.data; }, }); if (isLoading) { return (
); } const yachts = data ?? []; if (yachts.length === 0) { return ( ); } return (
Name Dimensions Hull Number Status {yachts.map((y) => { const dims = formatDimensions(y); const statusLabel = STATUS_LABELS[y.status] ?? y.status; const statusColor = STATUS_COLORS[y.status] ?? 'bg-muted text-muted-foreground border-muted'; return ( {y.name} {dims ? ( {dims} ) : ( )} {y.hullNumber ? ( {y.hullNumber} ) : ( )} {statusLabel} ); })}
); }