"use client"; import { useEffect } from "react"; import { createPortal } from "react-dom"; import CarouselCompetences from "./CarouselCompetences"; import { getApiUrl } from "../utils/getApiUrl"; interface ImageData { url: string; name?: string; formats?: { large?: { url: string; }; }; } interface GlossaireMot { mot_clef: string; description: string; images?: ImageData[]; } interface ModalGlossaireProps { mot: GlossaireMot; onClose: () => void; } export default function ModalGlossaire({ mot, onClose }: ModalGlossaireProps) { const apiUrl = getApiUrl(); // Verrouille le scroll du body + ferme sur Esc. useEffect(() => { document.body.classList.add("overflow-hidden"); const handleKey = (e: KeyboardEvent) => { if (e.key === "Escape") onClose(); }; window.addEventListener("keydown", handleKey); return () => { document.body.classList.remove("overflow-hidden"); window.removeEventListener("keydown", handleKey); }; }, [onClose]); const images = mot.images?.map((img) => ({ url: `${apiUrl}${img.formats?.large?.url || img.url}`, alt: img.name || "Illustration", })) || []; return createPortal(
{/* Carte interne : largeur fluide avec marge, hauteur capée, scroll interne si besoin. stopPropagation pour ne pas fermer la modale quand on interagit à l'intérieur. */}
e.stopPropagation()} >

{mot.mot_clef}

{mot.description}

{images.length > 0 ? ( ) : (

Aucune image disponible.

)}
, document.body ); }