"use client"; import Link from 'next/link'; import { IProjectAssignment } from '../../type.assignment'; import { HoverCard, HoverCardTrigger, HoverCardContent, } from '@/components/ui/hover-card'; import { FileText, ArrowUpRight, FolderGit2, Calendar, ArrowRight, } from 'lucide-react'; import BadgeStatus from '@/components/ui/badge-status'; import { formatAssignmentDate } from './AssignmentList'; interface ConvertedAssignmentBadgeProps { assignment: IProjectAssignment; clientId?: string | number; className?: string; } export default function ConvertedAssignmentBadge({ assignment, clientId, className = '', }: ConvertedAssignmentBadgeProps) { const isProject = !!assignment.wo_name; const effectiveClientId = clientId || assignment.client?.id; // --- CASE 1: Project Assignment converted from an IM --- const isConvertedFromIM = Boolean(isProject && (assignment.im_id || assignment.im)); const imData = assignment.im; const imId = assignment.im_id || imData?.id; const imName = imData?.im_name || assignment.im_name || 'Internal Memo'; const imCode = imData?.im_code || assignment.im_code; const imStartDate = imData?.im_start_date || assignment.im_start_date; const imEndDate = imData?.im_end_date || assignment.im_end_date; const imDescription = imData?.im_description || assignment.im_description; const imDetailUrl = effectiveClientId && imId ? `/task/client-detail/${effectiveClientId}/${imId}` : null; // --- CASE 2: IM Assignment that has been converted to 1 or more Projects --- const listWo = assignment.list_wo || []; const isConvertedIM = Boolean(!isProject && listWo.length > 0); // If neither condition applies, render nothing if (!isConvertedFromIM && !isConvertedIM) { return null; } // --- RENDER CASE 1: Project Assignment converted from an IM --- if (isConvertedFromIM) { return ( e.stopPropagation()} className={`inline-flex items-center gap-1 text-[10px] font-semibold px-2 py-0.5 rounded-full bg-purple-500/10 text-purple-700 dark:text-purple-400 border border-purple-500/25 hover:bg-purple-500/20 hover:border-purple-500/40 transition-all cursor-pointer shrink-0 select-none ${className}`} > Converted from IM e.stopPropagation()} className="w-80 sm:w-92 p-0 shadow-2xl border-border/80 bg-popover/98 backdrop-blur-md rounded-xl overflow-hidden z-50 text-left" > {/* Header: Origin indicator & IM Code */} Originating Memo {imCode && ( #{imCode} )} {/* Body: Title, Period, and Description callout */} {imName} {(imStartDate || imEndDate) && ( {formatAssignmentDate(imStartDate)} – {formatAssignmentDate(imEndDate)} )} {imDescription ? ( {imDescription} ) : null} {/* Footer: Direct Navigation Action */} {imDetailUrl && ( View Internal Memo )} ); } // --- RENDER CASE 2: IM Assignment that has been converted to Project(s) --- return ( e.stopPropagation()} className={`inline-flex items-center gap-1 text-[10px] font-semibold px-2 py-0.5 rounded-full bg-emerald-500/10 text-emerald-700 dark:text-emerald-300 border border-emerald-500/25 hover:bg-emerald-500/20 hover:border-emerald-500/40 transition-all cursor-pointer shrink-0 select-none ${className}`} > Converted to {listWo.length} Project{listWo.length > 1 ? 's' : ''} e.stopPropagation()} className="w-88 sm:w-104 p-0 shadow-2xl border-border/80 bg-popover/98 backdrop-blur-md rounded-xl overflow-hidden z-50 text-left" > {/* Header: Title, Total Count, and Shortcut Hint */} Converted Work Orders {listWo.length} Click row to open {/* Body: High-craft flat row list (NO box-in-box nesting!) */} {listWo.map((woItem, i) => { const woDetailUrl = effectiveClientId && woItem.id ? `/task/client-detail/${effectiveClientId}/${woItem.id}` : null; const woTitle = woItem.wo_name || woItem.project?.name || 'Untitled Project'; const RowContent = ( {/* Top Line: Title, Code Tag, Arrow Cue */} {woTitle} {woItem.project_assignment_status?.name && ( )} {/* Bottom Line: Clean Schedule & Status Badge */} {formatAssignmentDate(woItem.wo_start_date)} – {formatAssignmentDate(woItem.wo_end_date)} ); if (woDetailUrl) { return ( {RowContent} ); } return ( {RowContent} ); })} {/* Footer: Quiet context summary */} Generated from this Internal Memo {listWo.length} {listWo.length === 1 ? 'assignment' : 'assignments'} ); }
{formatAssignmentDate(imStartDate)} – {formatAssignmentDate(imEndDate)}
{imDescription}