import { IClient } from '../../types'; import { motion } from 'motion/react'; import { Card900, CardContent } from '@/components/ui/card'; import Link from 'next/link'; import { LazyImage } from '@/components/ui/lazy-image'; import { ExternalLink, MoreHorizontal, FolderGit2, FileText, Users } from 'lucide-react'; 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 { cn } from '@/lib/utils'; import BadgeStatus from '@/components/ui/badge-status'; import { Button } from '@/components/ui/button'; 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 imCount = 0; const projectCount = client.total_project || 0; const woCount = client.total_work_order || 0; const userCount = client.total_user_assigned || client.users?.length || 0; const isActive = client.status_name?.toLowerCase() === 'active'; const hasDescription = typeof client.description === 'string' && client.description.trim().length > 0; return ( {/* Left Column: Photo / Thumbnail (uncropped) */}
{/* Middle Column: Details, Description, Metrics & Breakdown */}
{/* Header Row: Code + Name + Status */}
{client.code && ( {client.code} )} {client.name}
{/* Status Pill with HoverCard */}
Status Summary

Status summary from WO or IM related to this client.

{client.project_status_summary?.length > 0 ? ( client.project_status_summary.map((item, key) => (
{item.total}
)) ) : ( No status summary recorded. )}
{/* Description & Narrative */}
{hasDescription && (

{client.description}

)}

{projectCount === 0 && imCount === 0 && woCount === 0 ? ( "No active projects, internal memos, or work orders recorded for this client yet." ) : ( <> {(projectCount > 0 || imCount > 0) && ( <> Currently managing a portfolio of{" "} {projectCount > 0 && ( {projectCount} project{projectCount > 1 ? 's' : ''} )} {projectCount > 0 && imCount > 0 && " and "} {imCount > 0 && ( {imCount} internal memo{imCount > 1 ? 's' : ''} )} .{" "} )} {woCount > 0 && ( <> A dedicated team of{" "} {userCount} experts is handling{" "} {woCount} work order{woCount > 1 ? 's' : ''} {" "} to ensure successful delivery for {client.name}. )} )}

{/* Metrics Bar & Status Breakdown */}
{projectCount} Projects
{woCount} Work Orders
{userCount} Assigned
{/* Project Status Summary items inline */} {client.project_status_summary && client.project_status_summary.length > 0 && (
{client.project_status_summary.slice(0, 3).map((item, key) => (
({item.total})
))}
)}
{/* Right Column: Assigned Team & Action Buttons */}
{/* Assigned Team */}
Assigned Team {client.users?.length || 0}
{client.users?.slice(0, 5).map((user, key) => (

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

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

))} {client.users?.length > 5 && (
+{client.users.length - 5}
)} {(!client.users || client.users.length === 0) && ( No team assigned )}
{/* Action buttons */}
View Client Detail onEdit(client)}> Edit Client onDelete(client)} className="text-destructive focus:text-destructive" > Delete Client
); }) }
); }