'use client'; import { useState } from 'react'; import { useParams } from 'next/navigation'; import { useQuery } from '@tanstack/react-query'; import { Plus } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { PermissionGate } from '@/components/shared/permission-gate'; import { EmptyState } from '@/components/shared/empty-state'; import { ReservationList, type ReservationRow } from '@/components/reservations/reservation-list'; import { BerthReserveDialog } from '@/components/reservations/berth-reserve-dialog'; import { useRealtimeInvalidation } from '@/hooks/use-realtime-invalidation'; import { apiFetch } from '@/lib/api/client'; interface BerthReservationsTabProps { berthId: string; } export function BerthReservationsTab({ berthId }: BerthReservationsTabProps) { const routeParams = useParams<{ portSlug: string }>(); const portSlug = routeParams?.portSlug ?? ''; const [reserveOpen, setReserveOpen] = useState(false); const { data, isLoading } = useQuery<{ data: ReservationRow[]; pagination?: unknown }>({ queryKey: ['berths', berthId, 'reservations'], queryFn: () => apiFetch( `/api/v1/berths/${berthId}/reservations?page=1&limit=50&order=desc&includeArchived=false`, ), }); useRealtimeInvalidation({ 'berth_reservation:created': [['berths', berthId, 'reservations']], 'berth_reservation:activated': [['berths', berthId, 'reservations']], 'berth_reservation:ended': [['berths', berthId, 'reservations']], 'berth_reservation:cancelled': [['berths', berthId, 'reservations']], }); const reservations = data?.data ?? []; const active = reservations.find((r) => r.status === 'active'); const history = reservations.filter((r) => r.status !== 'active'); return (

Reservations

{/* Active reservation card */} Active reservation {active ? ( ) : (

No active reservation.

)}
{/* History */} History {isLoading ? (

Loading…

) : history.length === 0 ? ( ) : ( )}
); }