'use client'; import { Anchor, Archive, Compass, MessageSquare, MoreHorizontal, Pencil } from 'lucide-react'; import { formatDistanceToNowStrict } from 'date-fns'; import { Button } from '@/components/ui/button'; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from '@/components/ui/dropdown-menu'; import { TagBadge } from '@/components/shared/tag-badge'; import { ListCard, ListCardAvatar, ListCardMeta, deriveInitials, } from '@/components/shared/list-card'; import { cn } from '@/lib/utils'; import { stageBadgeClass, stageDotClass, stageLabel as toStageLabel } from '@/lib/constants'; import { computeUrgencyBadges } from '@/components/interests/urgency'; import type { InterestRow } from './interest-columns'; const CATEGORY_LABELS: Record = { general_interest: 'General', specific_qualified: 'Qualified', hot_lead: 'Hot lead', }; const SOURCE_LABELS: Record = { website: 'Website', manual: 'Manual', referral: 'Referral', broker: 'Broker', }; interface InterestCardProps { interest: InterestRow; portSlug: string; onEdit: (interest: InterestRow) => void; onArchive: (interest: InterestRow) => void; } export function InterestCard({ interest, portSlug, onEdit, onArchive }: InterestCardProps) { const stageLabel = toStageLabel(interest.pipelineStage); const stagePill = stageBadgeClass(interest.pipelineStage); const accentClass = stageDotClass(interest.pipelineStage); const isHotLead = interest.leadCategory === 'hot_lead'; const categoryLabel = interest.leadCategory ? CATEGORY_LABELS[interest.leadCategory] : null; const sourceLabel = interest.source ? (SOURCE_LABELS[interest.source] ?? interest.source) : null; const tags = interest.tags ?? []; const notesCount = interest.notesCount ?? 0; const urgencyBadges = computeUrgencyBadges(interest); const clientName = interest.clientName ?? 'Unknown client'; const berthLabel = interest.berthMooringNumber; const lastIso = interest.dateLastContact ?? interest.updatedAt ?? null; const lastActivity = lastIso ? formatDistanceToNowStrict(new Date(lastIso), { addSuffix: true }) : null; return ( onEdit(interest)}> Edit onArchive(interest)}> Archive } >
{/* Title row: name + comment-icon when notes exist + spacer for actions */}

{clientName}

{notesCount > 0 ? ( ) : null}
{/* Berth or general-interest line */}

{berthLabel ? ( <> {berthLabel} ) : ( <> General interest )}

{/* Stage pill + category + source */}
{stageLabel} {isHotLead ? ( Hot ) : null} {(categoryLabel && !isHotLead) || sourceLabel ? (
{categoryLabel && !isHotLead ? {categoryLabel} : null} {categoryLabel && !isHotLead && sourceLabel ? ยท : null} {sourceLabel ? {sourceLabel} : null}
) : null}
{urgencyBadges.length > 0 ? (
{urgencyBadges.map((b) => ( {b.label} ))}
) : null} {tags.length > 0 ? (
{tags.slice(0, 2).map((tag) => ( ))} {tags.length > 2 ? ( +{tags.length - 2} ) : null}
) : null} {lastActivity ? (

Last activity {lastActivity}

) : null}
); }