/* global React, LINKS, Icon */
const { useState, useEffect, useRef } = React;
/* ============== Modal shell ============== */
function Modal({ open, onClose, children, className = "", labelClose = "Cerrar" }) {
useEffect(() => {
if (!open) return;
const onKey = (e) => { if (e.key === "Escape") onClose(); };
document.addEventListener("keydown", onKey);
document.body.style.overflow = "hidden";
return () => {
document.removeEventListener("keydown", onKey);
document.body.style.overflow = "";
};
}, [open, onClose]);
if (!open) return null;
return (
e.stopPropagation()} role="dialog" aria-modal="true">
{Icon.close(18)}
{children}
);
}
/* ============== About modal (sells) ============== */
function AboutModal({ t, lang, open, onClose }) {
const m = t.modals.about;
const waHref = `https://wa.me/${LINKS.whatsapp}?text=${encodeURIComponent(
lang === "es" ? "Hola Guillermina, me gustaría agendar mi primera cita." : "Hi Guillermina, I'd like to book my first session.")}`;
return (
{m.eyebrow}
{m.title.split("\n").map((l, i) => {l} )}
{m.intro}
{t.about.p1}
{t.about.p2}
{t.about.p3}
{t.about.p4}
{m.credTitle}
{t.about.credGroups.map((g, i) =>
{g.h}
{g.items.map((it, j) => {it} )}
)}
);
}
/* ============== Testimonials modal (3 moving) ============== */
function TestimonialsModal({ t, open, onClose }) {
const items = t.testimonials.items;
const m = t.modals.testimonials;
const [idx, setIdx] = useState(0);
const [perView, setPerView] = useState(1);
useEffect(() => {
const calc = () => {
const w = window.innerWidth;
setPerView(w < 600 ? 1 : 1.08);
};
calc();
window.addEventListener("resize", calc);
return () => window.removeEventListener("resize", calc);
}, []);
const maxIdx = Math.max(0, Math.ceil(items.length - perView));
useEffect(() => { setIdx((i) => Math.min(i, maxIdx)); }, [maxIdx]);
useEffect(() => {
if (!open) return;
const id = setInterval(() => setIdx((i) => (i >= maxIdx ? 0 : i + 1)), 4500);
return () => clearInterval(id);
}, [open, maxIdx]);
return (
{m.eyebrow}
{m.title}
{m.sub}
{items.map((tt, i) =>
"
{tt.tag && {tt.tag} }
{tt.q}
{tt.a.slice(0, 1)}
{tt.a} {tt.loc}
{"★★★★★"}
)}
{Array.from({ length: maxIdx + 1 }).map((_, i) =>
setIdx(i)} aria-label={`Slide ${i + 1}`}>
)}
setIdx((i) => Math.max(0, i - 1))} disabled={idx === 0}>{Icon.chev("left")}
setIdx((i) => Math.min(maxIdx, i + 1))} disabled={idx === maxIdx}>{Icon.chev("right")}
);
}
/* ============== Credentials / Formación modal ============== */
function CredentialsModal({ t, open, onClose }) {
const m = t.modals.credentials;
return (
{m.eyebrow}
{m.title}
{m.sub}
{m.institutionsTitle}
{t.trust.items.map((it, i) =>
{it}
)}
{t.modals.about.credTitle}
{t.about.credGroups.map((g, i) =>
{g.h}
{g.items.map((it, j) => {it} )}
)}
);
}
Object.assign(window, { Modal, AboutModal, TestimonialsModal, CredentialsModal });