'use client'; import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'; import { useParams } from 'next/navigation'; import type { DetailTab } from '@/components/shared/detail-layout'; import { InlineEditableField } from '@/components/shared/inline-editable-field'; import { InlineTagEditor } from '@/components/shared/inline-tag-editor'; import { NotesList } from '@/components/shared/notes-list'; import { ReservationList, type ReservationRow } from '@/components/reservations/reservation-list'; import { YachtOwnershipHistory } from '@/components/yachts/yacht-ownership-history'; import { apiFetch } from '@/lib/api/client'; type YachtPatchField = | 'name' | 'hullNumber' | 'registration' | 'flag' | 'yearBuilt' | 'builder' | 'model' | 'hullMaterial' | 'lengthFt' | 'widthFt' | 'draftFt' | 'lengthM' | 'widthM' | 'draftM' | 'status' | 'notes'; const STATUS_OPTIONS = [ { value: 'active', label: 'Active' }, { value: 'retired', label: 'Retired' }, { value: 'sold_away', label: 'Sold away' }, ]; interface YachtTabsYacht { id: string; name: string; hullNumber: string | null; registration: string | null; flag: string | null; yearBuilt: number | null; builder: string | null; model: string | null; hullMaterial: string | null; lengthFt: string | null; widthFt: string | null; draftFt: string | null; lengthM: string | null; widthM: string | null; draftM: string | null; status: string; notes: string | null; tags?: Array<{ id: string; name: string; color: string }>; } interface YachtTabsOptions { yachtId: string; currentUserId?: string; yacht: YachtTabsYacht; } function useYachtPatch(yachtId: string) { const qc = useQueryClient(); return useMutation({ mutationFn: async (patch: Partial>) => apiFetch(`/api/v1/yachts/${yachtId}`, { method: 'PATCH', body: patch, }), onSuccess: () => { qc.invalidateQueries({ queryKey: ['yachts', yachtId] }); }, }); } function EditableRow({ label, children }: { label: string; children: React.ReactNode }) { return (
{label}
{children}
); } function OverviewTab({ yachtId, yacht }: { yachtId: string; yacht: YachtTabsYacht }) { const mutation = useYachtPatch(yachtId); const save = (field: YachtPatchField, transform?: (v: string | null) => string | number | null) => async (next: string | null) => { const value = transform ? transform(next) : next; await mutation.mutateAsync({ [field]: value }); }; const numericString = (next: string | null) => (next === null ? null : next); const yearTransform = (next: string | null) => { if (next === null) return null; const n = Number.parseInt(next, 10); return Number.isNaN(n) ? null : n; }; return (
{/* Identity */}

Identity

{/* Build */}

Build

{/* Dimensions (ft) */}

Dimensions (ft)

{/* Dimensions (m) */}

Dimensions (m)

{/* Notes */}

Notes

{/* Tags */}

Tags

); } function YachtInterestsTab({ yachtId }: { yachtId: string }) { const { data, isLoading } = useQuery<{ data: Array<{ id: string; pipelineStage: string; clientName: string | null; berthMooringNumber: string | null; updatedAt: string; }>; }>({ queryKey: ['interests', 'by-yacht', yachtId], queryFn: () => apiFetch(`/api/v1/interests?yachtId=${yachtId}&limit=50&order=desc`), }); const interests = data?.data ?? []; if (isLoading) return

Loading…

; if (interests.length === 0) { return

No interests linked to this yacht.

; } return ( ); } function YachtReservationsTab({ yachtId }: { yachtId: string }) { const routeParams = useParams<{ portSlug: string }>(); const portSlug = routeParams?.portSlug ?? ''; const { data, isLoading } = useQuery<{ data: ReservationRow[] }>({ queryKey: ['berth-reservations', 'by-yacht', yachtId], queryFn: () => apiFetch(`/api/v1/berth-reservations?yachtId=${yachtId}&limit=50&order=desc`), }); if (isLoading) return

Loading…

; return ( ); } export function getYachtTabs({ yachtId, currentUserId, yacht }: YachtTabsOptions): DetailTab[] { return [ { id: 'overview', label: 'Overview', content: , }, { id: 'ownership-history', label: 'Ownership History', content: , }, { id: 'interests', label: 'Interests', content: , }, { id: 'reservations', label: 'Reservations', content: , }, { id: 'notes', label: 'Notes', content: , }, ]; }