"use client"; import { useEffect, useState } from "react"; type Slot = { id: string; slug: string; label: string; sport: string; time: string; capacity: number; booked: number; isFull: boolean; }; export default function Availability({ sport, }: { sport: "muay-thai" | "yoga"; }) { const [slots, setSlots] = useState([]); useEffect(() => { fetch("/api/classes") .then((r) => r.json()) .then((d) => setSlots( (Array.isArray(d) ? d : []).filter((s: Slot) => s.sport === sport) ) ) .catch(() => {}); }, [sport]); if (slots.length === 0) return null; return (
{slots.map((slot) => { const remaining = Math.max(0, slot.capacity - slot.booked); const isFull = slot.isFull || remaining === 0; return (

{slot.label}

{slot.time}

{isFull ? ( ❌ COMPLET ) : remaining <= 3 ? ( ⚡ Plus que {remaining}{" "} place{remaining > 1 ? "s" : ""} ! ) : ( {remaining} places libres )}
); })}
); }