"use client";
import { IProjectAssignment } from '../../type.assignment';
import { CLIENT_FALLBACK_IMAGE, END_USER_FALLBACK_IMAGE } from '../../types';
import { motion } from 'motion/react';
import { Card900 } from '@/components/ui/card';
import { Badge } from '@/components/ui/badge';
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 { LazyImage } from '@/components/ui/lazy-image';
import { Briefcase, Calendar, ExternalLink, MoreVertical, FolderGit2, FileText } from 'lucide-react';
import Link from 'next/link';
import BadgeStatus from '@/components/ui/badge-status';
import { formatAssignmentDate } from './AssignmentList';
interface AssignmentGridProps {
assignments: IProjectAssignment[];
clientId?: string;
onManageTeam?: (assignment: IProjectAssignment) => void;
onUpdateStatus?: (assignment: IProjectAssignment) => void;
onDelete?: (assignment: IProjectAssignment) => void;
}
export default function AssignmentGrid({
assignments,
clientId,
onManageTeam,
onUpdateStatus,
onDelete,
}: AssignmentGridProps) {
return (
{assignments.map((assignment, index) => {
const isProject = !!assignment.wo_name;
const assignmentType = isProject ? 'Work Order' : 'Internal Memo';
const assignmentName = assignment.wo_name || assignment.im_name || assignment.project?.name || 'Untitled Assignment';
const assignmentCode = assignment.wo_code || assignment.im_code || assignment.project?.code;
const assignmentStartDate = assignment.wo_start_date || assignment.im_start_date || assignment.project?.start_date;
const assignmentEndDate = assignment.wo_end_date || assignment.im_end_date || assignment.project?.end_date;
const assignmentDesc = assignment.wo_description || assignment.im_description || assignment.project?.description;
const assignmentStatus = assignment.project?.status || assignment.project_assignment_status?.name;
const illustrationSrc = isProject
? '/assets/illustrations/work_order.jpg'
: '/assets/illustrations/internal_memo.jpg';
const effectiveClientId = clientId || assignment.client?.id;
const assignmentDetailUrl = effectiveClientId ? `/task/client-detail/${effectiveClientId}/${assignment.id}` : '#';
const projectDetailUrl = effectiveClientId && assignment.project?.id
? `/task/client-detail/${effectiveClientId}/project-detail/${assignment.project.id}`
: null;
const editAssignmentUrl = effectiveClientId
? `/task/client-detail/${effectiveClientId}/project-assignments?is_edit=true&assignment_id=${assignment.id}`
: null;
return (
{/* Top Section: 3D Emblem, Badges, and Action Menu */}
{/* 3D App Icon / Emblem */}
{/* Identity & Badges */}
{isProject ? : }
{assignmentType}
{assignmentStatus && }
{assignmentCode && (
# {assignmentCode}
)}
{/* Actions Menu */}
View Assignment Details
{projectDetailUrl && (
View Project Details
)}
{!clientId && assignment.client?.id && (
View Client
)}
{editAssignmentUrl && (
Edit Assignment
)}
{onManageTeam && (
onManageTeam(assignment)}>
Manage Team
)}
{onUpdateStatus && (
onUpdateStatus(assignment)}>
Update Technical Status
)}
{onDelete && (
onDelete(assignment)}
className="text-destructive focus:text-destructive"
>
Delete
)}
{/* Center: Title, Project, Description, Tags */}
{/* Title */}
{assignmentName}
{/* Project Reference */}
{assignment.project?.name && (
Project:
{projectDetailUrl ? (
{assignment.project.name}
) : (
{assignment.project.name}
)}
)}
{/* Description */}
{assignmentDesc && (
{assignmentDesc}
)}
{/* Client & End User Badges */}
{assignment.client?.name && !clientId && (
Client:
{assignment.client.name}
)}
{assignment.end_user?.name && (
End User:
{assignment.end_user.name}
)}
{/* Footer: Timeline & Team Members */}
{formatAssignmentDate(assignmentStartDate)} - {formatAssignmentDate(assignmentEndDate)}
{/* Assigned Team */}
{assignment.project_assignment_work_order_detail?.slice(0, 4).map((item, key) => (
{item?.user?.fullname || item?.user?.name}
{item?.user?.position?.name || 'Team Member'}
))}
{assignment.project_assignment_work_order_detail && assignment.project_assignment_work_order_detail.length > 4 && (
+{assignment.project_assignment_work_order_detail.length - 4}
)}
{(!assignment.project_assignment_work_order_detail || assignment.project_assignment_work_order_detail.length === 0) && (
No team
)}
);
})}
);
}