import React from "react"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Progress } from "@/components/ui/progress"; import { LeaveBalance as LeaveBalanceType } from "@/types"; import { cn } from "@/lib/utils"; import { Loader2 } from "lucide-react"; interface LeaveBalanceDisplayProps { balances: LeaveBalanceType[]; year: number; isLoading?: boolean; } const LeaveBalance: React.FC = ({ balances, year, isLoading = false, }) => { // Function to calculate percentage used const calculatePercentage = (used: number, total: number) => { if (total === 0) return 0; return Math.min((used / total) * 100, 100); // Cap at 100% }; // Map leave master IDs to types and colors const leaveTypeMap: Record = { 4: { label: "Annual Leave", color: "bg-blue-500" }, 5: { label: "Sick Leave", color: "bg-red-500" }, 6: { label: "Personal Leave", color: "bg-green-500" }, 7: { label: "Unpaid Leave", color: "bg-gray-500" }, 8: { label: "Maternity Leave", color: "bg-pink-500" }, 9: { label: "Paternity Leave", color: "bg-purple-500" }, 10: { label: "Compensatory Leave", color: "bg-orange-500" }, 11: { label: "Bereavement Leave", color: "bg-slate-500" }, 13: { label: "Half Day Leave", color: "bg-amber-500" }, }; if (isLoading) { return ( Leave Balance ({year})
); } if (!balances || balances.length === 0) { return ( Leave Balance ({year})

No leave balance information available

); } return ( Leave Balance ({year})
{balances.map((balance) => { const typeInfo = leaveTypeMap[balance.leavesMasterId] || { label: `Leave Type ${balance.leavesMasterId}`, color: "bg-gray-500" }; const percentage = calculatePercentage(balance.used, balance.allocated); const remaining = balance.pending; return (
{typeInfo.label} {balance.allocated === 0 ? ( Unlimited ) : ( {remaining} of {balance.allocated} days left )}
{balance.carryForward > 0 && (
Includes {balance.carryForward} carried forward days
)}
); })}
); }; export default LeaveBalance;