'use client'; import { useState } from 'react'; import { useMutation, useQueryClient } from '@tanstack/react-query'; import { Pencil, Archive, RotateCcw, TrendingUp } from 'lucide-react'; import Link from 'next/link'; import { Button } from '@/components/ui/button'; import { Badge } from '@/components/ui/badge'; import { TagBadge } from '@/components/shared/tag-badge'; import { ArchiveConfirmDialog } from '@/components/shared/archive-confirm-dialog'; import { PermissionGate } from '@/components/shared/permission-gate'; import { InterestForm } from '@/components/interests/interest-form'; import { InterestStagePicker } from '@/components/interests/interest-stage-picker'; import { apiFetch } from '@/lib/api/client'; const STAGE_LABELS: Record = { open: 'Open', details_sent: 'Details Sent', in_communication: 'In Communication', visited: 'Visited', signed_eoi_nda: 'Signed EOI/NDA', deposit_10pct: 'Deposit 10%', contract: 'Contract', completed: 'Completed', }; const STAGE_COLORS: Record = { open: 'bg-slate-100 text-slate-700', details_sent: 'bg-blue-100 text-blue-700', in_communication: 'bg-sky-100 text-sky-700', visited: 'bg-violet-100 text-violet-700', signed_eoi_nda: 'bg-amber-100 text-amber-700', deposit_10pct: 'bg-orange-100 text-orange-700', contract: 'bg-green-100 text-green-700', completed: 'bg-emerald-100 text-emerald-700', }; const CATEGORY_LABELS: Record = { general_interest: 'General Interest', specific_qualified: 'Specific Qualified', hot_lead: 'Hot Lead', }; interface InterestDetailHeaderProps { portSlug: string; interest: { id: string; clientId: string; clientName: string | null; berthId: string | null; berthMooringNumber: string | null; pipelineStage: string; leadCategory: string | null; source: string | null; notes: string | null; reminderEnabled: boolean; reminderDays: number | null; archivedAt: string | null; tags?: Array<{ id: string; name: string; color: string }>; }; } export function InterestDetailHeader({ portSlug, interest }: InterestDetailHeaderProps) { const queryClient = useQueryClient(); const [editOpen, setEditOpen] = useState(false); const [archiveOpen, setArchiveOpen] = useState(false); const [stageOpen, setStageOpen] = useState(false); const isArchived = !!interest.archivedAt; const archiveMutation = useMutation({ mutationFn: () => apiFetch(`/api/v1/interests/${interest.id}`, { method: 'DELETE' }), onSuccess: () => { queryClient.invalidateQueries({ queryKey: ['interests', interest.id] }); queryClient.invalidateQueries({ queryKey: ['interests'] }); setArchiveOpen(false); }, }); const restoreMutation = useMutation({ mutationFn: () => apiFetch(`/api/v1/interests/${interest.id}/restore`, { method: 'POST' }), onSuccess: () => { queryClient.invalidateQueries({ queryKey: ['interests', interest.id] }); queryClient.invalidateQueries({ queryKey: ['interests'] }); setArchiveOpen(false); }, }); return ( <>

{interest.clientName ?? 'Unknown Client'}

{isArchived && ( Archived )} {STAGE_LABELS[interest.pipelineStage] ?? interest.pipelineStage}
{interest.berthMooringNumber && ( Berth:{' '} {interest.berthMooringNumber} )} {interest.leadCategory && ( Category:{' '} {CATEGORY_LABELS[interest.leadCategory] ?? interest.leadCategory} )} {interest.source && ( Source:{' '} {interest.source} )}
{interest.tags && interest.tags.length > 0 && (
{interest.tags.map((tag) => ( ))}
)}
{/* Actions */}
[0]['interest']} /> { if (isArchived) { restoreMutation.mutate(); } else { archiveMutation.mutate(); } }} isLoading={archiveMutation.isPending || restoreMutation.isPending} /> ); }