import React from "react"; import { Button } from "@/components/ui/button"; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; import { Alert, AlertDescription } from "@/components/ui/alert"; import { Badge } from "@/components/ui/badge"; import { AlertTriangle, Clock, DollarSign, Calendar, Users } from "lucide-react"; import { format, differenceInHours } from "date-fns"; // Calculate if cancellation fee applies export const calculateCancellationFee = (eventDate, eventStartTime, assignedCount) => { const now = new Date(); // Combine event date and start time const eventDateTime = new Date(`${eventDate}T${eventStartTime || '00:00'}`); const hoursUntilEvent = differenceInHours(eventDateTime, now); // Rule: 24+ hours = no fee, < 24 hours = 4-hour fee per worker const feeApplies = hoursUntilEvent < 24; const feeAmount = feeApplies ? assignedCount * 4 * 50 : 0; // Assuming $50/hour average return { feeApplies, hoursUntilEvent, feeAmount, assignedCount }; }; export default function CancellationFeeModal({ open, onClose, onConfirm, event, isSubmitting }) { if (!event) return null; const eventStartTime = event.shifts?.[0]?.roles?.[0]?.start_time || '09:00'; const assignedCount = event.assigned_staff?.length || 0; const feeData = calculateCancellationFee(event.date, eventStartTime, assignedCount); return (
Confirm Order Cancellation {feeData.feeApplies ? "⚠️ Cancellation fee will apply" : "✅ No cancellation fee" }
{/* Event Summary */}

{event.event_name}

{format(new Date(event.date), 'MMM d, yyyy')}
{eventStartTime}
{assignedCount} Staff Assigned
{/* Time Until Event */}
{feeData.hoursUntilEvent} hours until event

{feeData.feeApplies ? "Canceling within 24 hours triggers a 4-hour minimum fee per assigned worker." : "You're canceling more than 24 hours in advance - no penalty applies." }

{/* Fee Breakdown */} {feeData.feeApplies && (

Cancellation Fee Breakdown

Assigned Staff {assignedCount} workers
Minimum Charge 4 hours each
Total Cancellation Fee ${feeData.feeAmount.toLocaleString()}
)} {/* Warning Text */} ⚠️ This action cannot be undone. The vendor will be notified immediately, and all assigned staff will be released from this event.
); }