/* global React, useUI, useWishlist, Placeholder, HeartIcon, Arr, waLink */ const { useEffect } = React; function Modal() { const ui = useUI(); const wl = useWishlist(); const p = ui.modal; useEffect(() => { if (!p) return; const onKey = (e) => { if (e.key === "Escape") ui.closeModal(); }; window.addEventListener("keydown", onKey); document.body.style.overflow = "hidden"; return () => { window.removeEventListener("keydown", onKey); document.body.style.overflow = ""; }; }, [p]); if (!p) return null; const isOn = wl.has(p.id); // Handle both raw catalog format (nombre/foto/precio) and transformed format (name/photo/price) const name = p.name || p.nombre || ""; const photo = p.photo || p.foto || null; const price = p.price || (p.precio ? p.precio.toLocaleString("es-CO") : ""); const family = p.family || (p.categoria ? (window.CAT_LABELS && window.CAT_LABELS[p.categoria]) || p.categoria : ""); const pattern = p.pattern || (typeof detectarPatron === "function" ? detectarPatron(p.variante) : null) || ""; const variant = p.variante || ""; const wmsg = `Hola DAVA'S, me interesa la ${name}${pattern ? ` patrón ${pattern}` : ""}${price ? ` ($${price})` : ""}. ¿Me cuentan disponibilidad?`; return (