"use client"; import { useEffect } from "react"; import { createPortal } from "react-dom"; import CarouselCompetences from "./CarouselCompetences"; import { getApiUrl } from "../utils/getApiUrl"; import { pickStrapiImage, type StrapiMediaLike } from "../utils/strapiImage"; interface ImageData extends StrapiMediaLike { name?: 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: ImageData) => { const picked = pickStrapiImage(apiUrl, img, "full"); const url = picked?.src ?? (img.url || img.formats?.large?.url ? `${apiUrl}${img.formats?.large?.url ?? img.url}` : null); if (!url) return null; return { url, alt: img.name || "Illustration", }; }) .filter((item): item is { url: string; alt: string } => item != null) || []; return createPortal(
{mot.description}
Aucune image disponible.
)}