import React from "react"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Badge } from "@/components/ui/badge"; import { Progress } from "@/components/ui/progress"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"; import { Users, DollarSign, Clock, TrendingUp, TrendingDown, Building2, MapPin, Briefcase, AlertTriangle, CheckCircle } from "lucide-react"; import { BarChart, Bar, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer, Legend } from "recharts"; export default function LaborSpendAnalysis({ assignments, workforce, orders, metrics, userRole }) { // Generate channel breakdown const channelData = [ { channel: "Preferred Vendors", spend: metrics.contractedSpend * 0.6, workers: Math.floor(workforce.length * 0.4), efficiency: 94 }, { channel: "Approved Vendors", spend: metrics.contractedSpend * 0.4, workers: Math.floor(workforce.length * 0.25), efficiency: 88 }, { channel: "Gig Platforms", spend: metrics.nonContractedSpend * 0.5, workers: Math.floor(workforce.length * 0.2), efficiency: 72 }, { channel: "Agency Labor", spend: metrics.nonContractedSpend * 0.3, workers: Math.floor(workforce.length * 0.1), efficiency: 68 }, { channel: "Internal Pool", spend: metrics.nonContractedSpend * 0.2, workers: Math.floor(workforce.length * 0.05), efficiency: 91 }, ]; const utilizationData = [ { category: "Culinary Staff", utilized: 85, available: 100, cost: 45000 }, { category: "Event Staff", utilized: 78, available: 100, cost: 32000 }, { category: "Bartenders", utilized: 92, available: 100, cost: 28000 }, { category: "Security", utilized: 65, available: 100, cost: 18000 }, { category: "Facilities", utilized: 71, available: 100, cost: 15000 }, ]; const benchmarkData = [ { metric: "Cost per Hour", yours: metrics.avgNonContractedRate, benchmark: 42.50, industry: 48.00 }, { metric: "Fill Rate", yours: metrics.fillRate, benchmark: 95, industry: 88 }, { metric: "No-Show Rate", yours: metrics.noShowRate, benchmark: 2, industry: 5 }, { metric: "OT Percentage", yours: 12, benchmark: 8, industry: 15 }, ]; return (
{/* Channel Breakdown */} Labor Spend by Channel
Channel Spend Workers Efficiency Status {channelData.map((row, idx) => ( {row.channel} ${row.spend.toLocaleString(undefined, { maximumFractionDigits: 0 })} {row.workers}
{row.efficiency}%
= 85 ? "bg-green-100 text-green-700" : row.efficiency >= 70 ? "bg-amber-100 text-amber-700" : "bg-red-100 text-red-700"}> {row.efficiency >= 85 ? "Optimal" : row.efficiency >= 70 ? "Review" : "Optimize"}
))}
{/* Utilization Chart */}
Workforce Utilization by Category
[`${value}%`, 'Utilization']} contentStyle={{ background: 'white', border: '1px solid #e2e8f0', borderRadius: '8px' }} />
Cost by Category
{utilizationData.map((item, idx) => (

{item.category}

{item.utilized}% utilized

${item.cost.toLocaleString()}

monthly spend

))}
{/* Benchmarking */} Performance Benchmarking
{benchmarkData.map((item, idx) => { const isBetter = item.metric === "No-Show Rate" || item.metric === "OT Percentage" ? item.yours < item.benchmark : item.yours > item.benchmark; return (

{item.metric}

Your Rate {item.metric.includes("Rate") || item.metric.includes("Percentage") ? `${item.yours.toFixed(1)}%` : `$${item.yours.toFixed(2)}`}
Benchmark {item.metric.includes("Rate") || item.metric.includes("Percentage") ? `${item.benchmark}%` : `$${item.benchmark.toFixed(2)}`}
Industry Avg {item.metric.includes("Rate") || item.metric.includes("Percentage") ? `${item.industry}%` : `$${item.industry.toFixed(2)}`}
{isBetter ? : } {isBetter ? "Above Benchmark" : "Below Benchmark"}
); })}
{/* Contracted vs Non-Contracted Comparison */} Contracted vs. Non-Contracted Labor Analysis

Contracted Labor

{metrics.contractedRatio.toFixed(1)}% of total spend

Total Spend ${metrics.contractedSpend.toLocaleString(undefined, { maximumFractionDigits: 0 })}
Avg Rate ${metrics.avgContractedRate.toFixed(2)}/hr
Reliability 92%
Fill Rate 96%

Non-Contracted Labor

{(100 - metrics.contractedRatio).toFixed(1)}% of total spend

Total Spend ${metrics.nonContractedSpend.toLocaleString(undefined, { maximumFractionDigits: 0 })}
Avg Rate ${metrics.avgNonContractedRate.toFixed(2)}/hr
Reliability 71%
Fill Rate 78%
); }