"use client"; import { motion } from 'motion/react'; import Link from 'next/link'; import { ExternalLink, MoreHorizontal, FileText, Users, ClipboardList } from 'lucide-react'; import { Card900 } from '@/components/ui/card'; import { Button } from '@/components/ui/button'; import { LazyImage } from '@/components/ui/lazy-image'; 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 ClientGridProps { clients: IClient[]; onEdit: (client: IClient) => void; onDelete: (client: IClient) => void; } export default function ClientGrid({ clients, onEdit, onDelete }: ClientGridProps) { return (
{clients.map((client, i) => { const isActive = (client.status_name || '').toLowerCase() === 'active'; const stages = getProjectStatusBreakdown(client); const totalProjects = client.total_project ?? 0; const assignedPeople = client.total_user_assigned || client.users?.length || 0; const activeWorkOrders = client.total_work_order ?? 0; // Display all 7 stages const maxStageCount = 10; return ( {/* Card Top: Code + Status Pill with HoverCard + Actions Menu */}
{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. )}
{/* Dropdown Action Menu */} View Client Detail onEdit(client)}> Edit Client onDelete(client)} className="text-destructive focus:text-destructive" > Delete Client
{/* Client Brand Logo & Corporate Name */}
{client.name}
{/* 3 Metrics Quick Strip */}
Projects
{totalProjects}
Personnel
{assignedPeople}
Work Orders
{activeWorkOrders}
{/* Project Status Breakdown (Mini bars matching technical status colors) */}
Project Status Active Stages
{stages.map((stage) => { const barPercent = Math.min(100, (stage.count / maxStageCount) * 100); return (
{stage.name}
{stage.count}
); })}
{/* Next 2 Months Milestone Timeline */}
{/* Card Bottom: Team Avatars & View Detail button */}
{/* Team Avatars */}
{client.users?.slice(0, 4).map((user, key) => (

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

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

))} {client.users && client.users.length > 4 && (
+{client.users.length - 4}
)} {(!client.users || client.users.length === 0) && ( No team )}
); })}
); }