import React from 'react'; // Types for the component type Slot = { startTime: string; endTime: string; }; type Court = { courtId: string; courtName: string; sport: { id: string; name: string; slug: string }; slotDurationMinutes: number; availableSlots: Slot[]; }; type SelectedSlot = { courtId: string; startTime: string; } | null; type AvailabilityHeatMapProps = { courts: Court[]; selectedSlot: SelectedSlot; onSelectSlot: (payload: { courtId: string; courtName: string; sportId: string; sportName: string; startTime: string; endTime: string; price?: { min: number; max: number }; }) => void; }; /** * AvailabilityHeatMap * * A visual heat‑map style component that displays each court as a card and colours the * slot buttons according to how many slots are available for that court. The colour scale * goes from green (few slots) to red (many slots), providing an immediate visual cue of * density – the signature element requested for the bookings panel. */ export default function AvailabilityHeatMap({ courts, selectedSlot, onSelectSlot, }: AvailabilityHeatMapProps) { // Determine the maximum number of slots among all courts to normalise the heat scale. const maxSlots = Math.max(1, ...courts.map((c) => c.availableSlots.length)); // Convert a slot count into an HSL colour ranging from green (low) to red (high). const slotCountToHue = (count: number) => { const ratio = count / maxSlots; // 0 => green, 1 => red const hue = Math.round(120 - 120 * ratio); // 120° (green) to 0° (red) return `hsl(${hue}, 70%, 55%)`; }; return (
{courts.map((court) => { const bg = slotCountToHue(court.availableSlots.length); return (

{court.courtName}

{court.availableSlots.length} horarios
{court.availableSlots.map((slot) => { const isSelected = selectedSlot?.courtId === court.courtId && selectedSlot?.startTime === slot.startTime; return ( ); })}
); })}
); }