import React from "react"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"; import { Plus, Minus, Pencil, Trash2, Search } from "lucide-react"; import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, } from "@/components/ui/command"; import { Popover, PopoverContent, PopoverTrigger, } from "@/components/ui/popover"; const ROLES = [ "Front Desk", "Finance", "Hospitality", "Recruiter", "Server", "Bartender", "Cook", "Dishwasher", "Security", "Janitor" ]; const DEPARTMENTS = [ "Accounting", "Operations", "Sales", "HR", "Finance", "IT", "Marketing", "Customer Service", "Logistics" ]; const UNIFORMS = ["Type 1", "Type 2", "Type 3", "Casual", "Formal"]; const TIME_OPTIONS = []; for (let h = 1; h <= 12; h++) { for (let m of ['00', '30']) { TIME_OPTIONS.push(`${h.toString().padStart(2, '0')}:${m} AM`); } } for (let h = 1; h <= 12; h++) { for (let m of ['00', '30']) { TIME_OPTIONS.push(`${h.toString().padStart(2, '0')}:${m} PM`); } } export default function ShiftRolesTable({ roles, onChange }) { const handleAddRole = () => { onChange([...roles, { role: "", department: "", count: 1, start_time: "12:00 PM", end_time: "05:00 PM", hours: 5, uniform: "Type 1", break_minutes: 30, cost_per_hour: 45, total_value: 0 }]); }; const handleDeleteRole = (index) => { onChange(roles.filter((_, i) => i !== index)); }; const handleRoleChange = (index, field, value) => { const newRoles = [...roles]; newRoles[index] = { ...newRoles[index], [field]: value }; // Calculate hours if times changed if (field === 'start_time' || field === 'end_time') { const start = newRoles[index].start_time; const end = newRoles[index].end_time; const hours = calculateHours(start, end); newRoles[index].hours = hours; } // Calculate total value const count = newRoles[index].count || 0; const hours = newRoles[index].hours || 0; const cost = newRoles[index].cost_per_hour || 0; newRoles[index].total_value = count * hours * cost; onChange(newRoles); }; const calculateHours = (start, end) => { // Simple calculation - in production, use proper time library const startHour = parseInt(start.split(':')[0]) + (start.includes('PM') && !start.startsWith('12') ? 12 : 0); const endHour = parseInt(end.split(':')[0]) + (end.includes('PM') && !end.startsWith('12') ? 12 : 0); return Math.max(0, endHour - startHour); }; return (
# Role Department Count Start Date End Date Hours Uniform Break Cost Value Actions {roles.map((role, index) => ( {index + 1} {/* Role */} No role found. {ROLES.map((r) => ( handleRoleChange(index, 'role', r)} > {r} ))} {/* Department */} {/* Count */}
handleRoleChange(index, 'count', parseInt(e.target.value) || 1)} className="w-12 h-8 text-center p-0" />
{/* Start Time */} {/* End Time */} {/* Hours */} {role.hours} {/* Uniform */} {/* Break */} handleRoleChange(index, 'break_minutes', parseInt(e.target.value) || 0)} className="w-20 text-center" placeholder="30" /> {/* Cost */} handleRoleChange(index, 'cost_per_hour', parseFloat(e.target.value) || 0)} className="w-20 text-center" placeholder="45" /> {/* Value */} ${role.total_value?.toFixed(2) || '0.00'} {/* Actions */}
))}
{/* Add Role Button */}
); }