'use client'; import { useParams, useRouter } from 'next/navigation'; import type { Route } from 'next'; import { useState } from 'react'; import { Archive, Bell, RotateCcw, Trash2 } from 'lucide-react'; import { format } from 'date-fns'; import { Badge } from '@/components/ui/badge'; import { TagBadge } from '@/components/shared/tag-badge'; import { PermissionGate } from '@/components/shared/permission-gate'; import { SmartArchiveDialog } from '@/components/clients/smart-archive-dialog'; import { SmartRestoreDialog } from '@/components/clients/smart-restore-dialog'; import { HardDeleteDialog } from '@/components/clients/hard-delete-dialog'; import { ReminderForm } from '@/components/reminders/reminder-form'; import { useQueryClient } from '@tanstack/react-query'; import { DetailHeaderStrip } from '@/components/shared/detail-header-strip'; import { CountryFlag } from '@/components/shared/country-flag'; import { PortalInviteButton } from '@/components/clients/portal-invite-button'; import { GdprExportButton } from '@/components/clients/gdpr-export-button'; import { cn } from '@/lib/utils'; import { getCountryName } from '@/lib/i18n/countries'; interface ClientDetailHeaderProps { client: { id: string; fullName: string; nationalityIso?: string | null; archivedAt?: string | null; createdAt?: string; contacts?: Array<{ channel: string; value: string; valueE164?: string | null; isPrimary: boolean; label?: string | null; }>; tags?: Array<{ id: string; name: string; color: string }>; clientPortalEnabled?: boolean; }; } export function ClientDetailHeader({ client }: ClientDetailHeaderProps) { const router = useRouter(); const params = useParams<{ portSlug: string }>(); const portSlug = params?.portSlug ?? ''; const [archiveOpen, setArchiveOpen] = useState(false); const [hardDeleteOpen, setHardDeleteOpen] = useState(false); const [reminderOpen, setReminderOpen] = useState(false); const qc = useQueryClient(); const isArchived = !!client.archivedAt; const primaryEmail = client.contacts?.find((c) => c.channel === 'email' && c.isPrimary)?.value ?? client.contacts?.find((c) => c.channel === 'email')?.value; const country = client.nationalityIso ? getCountryName(client.nationalityIso, 'en') : null; const addedLabel = client.createdAt ? `Added ${format(new Date(client.createdAt), 'MMM d, yyyy')}` : null; return ( <>

{client.fullName}

{isArchived && ( Archived )}
{country || addedLabel ? (

{country ? ( {country} ) : null} {country && addedLabel ? ยท : null} {addedLabel ? {addedLabel} : null}

) : null} {/* CM-4: Email/Call/WhatsApp deep-link pills removed at client request. GDPR export moved to the top-right action cluster. Portal-invite stays as the one primary CTA here. */} {!isArchived && client.clientPortalEnabled === true ? (
) : null} {client.tags && client.tags.length > 0 && (
{client.tags.map((tag) => ( ))}
)}
{/* Top-right: archive/restore + (for archived clients with the right perm) permanently-delete. Destructive actions sit out of the primary action flow. */}
{/* CM-4: GDPR export relocated here as a compact icon trigger, alongside reminder/archive/delete. Self-gates on permission. */} {isArchived && ( )}
qc.invalidateQueries({ queryKey: ['reminders'] })} /> {isArchived ? ( ) : ( )} {isArchived && ( router.push(`/${portSlug}/clients` as Route)} /> )} ); }