import React, { useState } from "react"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Clock, MapPin, Users, DollarSign, UserPlus } from "lucide-react"; import SmartAssignModal from "./SmartAssignModal"; import AssignedStaffManager from "./AssignedStaffManager"; const convertTo12Hour = (time24) => { if (!time24 || time24 === "—") return time24; try { const parts = time24.split(':'); if (!parts || parts.length < 2) return time24; const hours = parseInt(parts[0], 10); const minutes = parseInt(parts[1], 10); if (isNaN(hours) || isNaN(minutes)) return time24; const period = hours >= 12 ? 'PM' : 'AM'; const hours12 = hours % 12 || 12; const minutesStr = minutes.toString().padStart(2, '0'); return `${hours12}:${minutesStr} ${period}`; } catch (error) { console.error('Error converting time:', error); return time24; } }; export default function ShiftCard({ shift, event }) { const [assignModal, setAssignModal] = useState({ open: false, role: null }); const roles = shift?.roles || []; return ( <> {shift.shift_name || "Shift"} {shift.location && ( {shift.location} )} {roles.length} Role{roles.length !== 1 ? 's' : ''} {roles.map((role, idx) => { const requiredCount = role.count || 1; const assignedCount = event?.assigned_staff?.filter(s => s.role === role.role)?.length || 0; const remainingCount = Math.max(requiredCount - assignedCount, 0); // Consistent status color logic const statusColor = remainingCount === 0 ? "bg-green-100 text-green-700 border-green-300" : assignedCount > 0 ? "bg-blue-100 text-blue-700 border-blue-300" : "bg-slate-100 text-slate-700 border-slate-300"; return ( {role.role} {assignedCount} / {requiredCount} Assigned {role.start_time && role.end_time && ( {convertTo12Hour(role.start_time)} - {convertTo12Hour(role.end_time)} )} {role.department && ( {role.department} )} {remainingCount > 0 && ( setAssignModal({ open: true, role })} className="bg-[#0A39DF] hover:bg-blue-700 gap-2 font-semibold" > Assign Staff ({remainingCount} needed) )} {/* Show assigned staff */} {assignedCount > 0 && ( Assigned Staff )} {/* Additional role details */} {(role.uniform || role.cost_per_hour) && ( {role.uniform && ( Uniform {role.uniform} )} {role.cost_per_hour && ( Rate ${role.cost_per_hour}/hr )} )} ); })} {/* Smart Assignment Modal */} setAssignModal({ open: false, role: null })} event={event} shift={shift} role={assignModal.role} /> > ); }
Assigned Staff
Uniform
{role.uniform}
Rate
${role.cost_per_hour}/hr