/**
* Documents tab on the berth detail page (Phase 6b - see plan §5.6).
*
* Sections:
* - Current PDF panel (download link, "Replace PDF" button, parse-engine chip).
* - Version history list - newest first, with rollback affordance on every
* non-current row.
* - Reconcile-diff dialog (PdfReconcileDialog), opened after a successful
* upload + parse. Shows auto-applied vs conflicted fields and lets the
* rep accept the conflict resolution.
*
* The actual upload is split in two steps:
* 1. POST /pdf-upload-url -> presigned URL + storageKey
* 2. PUT the file to that URL (multipart for filesystem-proxy mode, signed
* PUT for S3 mode)
* 3. POST /pdf-versions with the storage key + parse results
*/
'use client';
import { useRef, useState } from 'react';
import dynamic from 'next/dynamic';
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
import { toast } from 'sonner';
import { ChevronDown, ChevronRight, Download } from 'lucide-react';
import { apiFetch } from '@/lib/api/client';
import { toastError } from '@/lib/api/toast-error';
import { Button } from '@/components/ui/button';
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
import { Badge } from '@/components/ui/badge';
import { PdfReconcileDialog } from './pdf-reconcile-dialog';
// pdfjs-dist is ~150kb gzip — lazy-load so the berth page only pulls it
// in when a rep actually expands the spec-sheet preview. ssr:false
// because the pdfjs worker setup needs `window`.
const PdfViewer = dynamic(
() => import('@/components/files/pdf-viewer').then((m) => ({ default: m.PdfViewer })),
{
ssr: false,
loading: () => (
Berth-spec PDF: the dimensional drawing or surveyor sheet for this slip. Versioned so a
misparse can be rolled back. Deal documents (EOI, contract, etc.) live on the “Deal
Documents” tab.