"use client"; import { motion } from 'motion/react'; import Link from 'next/link'; import { FileText, Users, ClipboardList, MoreHorizontal, ExternalLink, Trash, PencilLine } from 'lucide-react'; import { Card900 } from '@/components/ui/card'; import { LazyImage } from '@/components/ui/lazy-image'; import { Button } from '@/components/ui/button'; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from '@/components/ui/dropdown-menu'; import { Tooltip, TooltipContent, TooltipTrigger, } from '@/components/ui/tooltip'; import { HoverCard, HoverCardContent, HoverCardTrigger, } from '@/components/ui/hover-card'; import BadgeStatus from '@/components/ui/badge-status'; import { cn } from '@/lib/utils'; import { IClient, CLIENT_FALLBACK_IMAGE } from '../../types'; import { getProjectStatusBreakdown } from '../../utils/client-overview-helpers'; import dynamic from 'next/dynamic'; const ClientMilestoneTimeline = dynamic(() => import('./ClientMilestoneTimeline'), { ssr: false, loading: () => (
), }); interface ClientListProps { clients: IClient[]; onEdit: (client: IClient) => void; onDelete: (client: IClient) => void; } export default function ClientList({ clients, onEdit, onDelete }: ClientListProps) { return (
{clients.map((client, index) => { const isActive = (client.status_name || '').toLowerCase() === 'active'; const stages = getProjectStatusBreakdown(client); const maxStageCount = 10; const totalProjects = client.total_project ?? 0; const assignedPeople = client.total_user_assigned || client.users?.length || 0; const activeWorkOrders = client.total_work_order ?? 0; return ( {/* Top Section: 3-column layout (Identity | Status Breakdown | Quick Stats) */}
{/* Left Column: Client Identity & Team (col-span-3) */}
{/* Code Badge + Status Pill with HoverCard */}
{client.code && ( {client.code}

Client Code

{client.code}

)} {/* Status Pill with Hover Content Summary Status */}
Status Summary

Status summary from WO or IM related to this client.

{client.project_status_summary && client.project_status_summary.length > 0 ? ( client.project_status_summary.map((item, key) => (
{item.total}
)) ) : ( No status summary recorded. )}
{/* Brand Logo Presentation */}
{/* Client Full Corporate Name */} {client.name} {/* Team Avatars */}
{client.users?.slice(0, 5).map((user, uKey) => (

{user?.name || user?.fullname}

{user?.position?.name || 'Team Member'}

))} {client.users && client.users.length > 5 && (
+{client.users.length - 5}
)} {(!client.users || client.users.length === 0) && ( No team assigned )}
{/* Middle Column: Project Status Breakdown (col-span-6) */}

Project Status

{stages.map((stage) => { const barPercent = Math.min(100, (stage.count / maxStageCount) * 100); return (
{/* Stage Name + Dot matching technical status */}
{stage.name}
{/* Progress Bar Container */}
{/* Count Number */} {stage.count}
); })}
{/* Right Column: Quick Stats & Actions (col-span-3) */}
Total Projects
{totalProjects}
Assigned People
{assignedPeople}
Work Orders
{activeWorkOrders}
{/* Action Buttons: View Detail + More Actions Dropdown */}
{/* Bottom Section: 2-Month Milestone Timeline */}
); })}
); }