// ====================== MOBILE CHROME (header + search + catnav + location) ====================== // Renderizado SÓ no mobile (≤860px). Não altera a estrutura desktop. function useIsMobile(bp = 860) { const q = `(max-width:${bp}px)`; const [m, setM] = React.useState(() => typeof window !== "undefined" && window.matchMedia ? window.matchMedia(q).matches : false ); React.useEffect(() => { const mq = window.matchMedia(q); const h = (e) => setM(e.matches); mq.addEventListener ? mq.addEventListener("change", h) : mq.addListener(h); return () => (mq.removeEventListener ? mq.removeEventListener("change", h) : mq.removeListener(h)); }, [q]); return m; } // pequeno coração (favoritos) — ícone genérico inline const IconHeartM = (p) => ( ); function MobileChrome({ cartCount = 0, onCart, onSearch, onNav, onOffers }) { const [q, setQ] = React.useState(""); const [drawer, setDrawer] = React.useState(false); const [focus, setFocus] = React.useState(false); const [items, setItems] = React.useState([]); const searchWrap = React.useRef(null); React.useEffect(() => { if (window.JGFCatalog && window.JGFCatalog.allItems) { window.JGFCatalog.allItems().then(setItems).catch(() => setItems([])); } }, []); React.useEffect(() => { const h = (e) => { if (searchWrap.current && !searchWrap.current.contains(e.target)) setFocus(false); }; document.addEventListener("mousedown", h); document.addEventListener("touchstart", h); return () => { document.removeEventListener("mousedown", h); document.removeEventListener("touchstart", h); }; }, []); const norm = (s) => (s || "").toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g, ""); const nq = norm(q.trim()); const filtered = nq ? items.filter((it) => norm(it.nome).startsWith(nq)).slice(0, 10) : []; const PAGES = (window.JGFCatalog && window.JGFCatalog.PAGES) || {}; const goItem = (it) => { const page = PAGES[it.secao]; setFocus(false); if (page) window.location.href = page + "?q=" + encodeURIComponent(it.nome); else onSearch(it.nome, "Todas as categorias"); }; React.useEffect(() => { document.body.style.overflow = drawer ? "hidden" : ""; return () => { document.body.style.overflow = ""; }; }, [drawer]); const navLinks = VISIBLE_CATEGORIES.map((c) => ({ id: c.id, label: c.label })); const iconBtn = { display: "flex", alignItems: "center", justifyContent: "center", width: 36, height: 40, borderRadius: 9, color: "#fff", position: "relative", flexShrink: 0, }; return (
{/* ---- barra principal (navy) ---- */}
JGF Distribuidora
{/* ---- busca ---- */}
{ e.preventDefault(); setFocus(false); onSearch(q, "Todas as categorias"); }} style={{ display: "flex", alignItems: "stretch", height: 46, borderRadius: 9, overflow: "hidden", background: "#fff" }}> setQ(e.target.value)} onFocus={() => setFocus(true)} placeholder="Digite aqui o que você procura" style={{ flex: 1, minWidth: 0, border: "none", outline: "none", padding: "0 15px", fontSize: 14.5, fontWeight: 500, color: "var(--ink)" }} />
{focus && filtered.length > 0 && (
{filtered.map((it) => ( ))}
)}
{/* ---- nav de categorias (rolagem horizontal) ---- */}
{navLinks.map((l, idx) => ( ))}
{/* ---- drawer de categorias ---- */} {drawer && (
setDrawer(false)} style={{ position: "fixed", inset: 0, background: "rgba(15,29,57,.5)", zIndex: 900, animation: "fadeUp .2s ease both" }}>
e.stopPropagation()} style={{ position: "absolute", top: 0, left: 0, bottom: 0, width: "82%", maxWidth: 320, background: "#fff", boxShadow: "0 0 40px rgba(0,0,0,.3)", display: "flex", flexDirection: "column", animation: "slideInLeft .26s cubic-bezier(.2,.9,.3,1) both" }}>
JGF
Categorias
{navLinks.map((l) => ( ))}
Sobre a JGF
)}
); } Object.assign(window, { MobileChrome, useIsMobile });