/* ============================================================ UVD CLUB — app (rota + carrinho + tweaks) ============================================================ */ const TWEAK_DEFAULTS = /*EDITMODE-BEGIN*/{ "homeDir": "atelier", "accent": "#7C1D2B", "fontScale": 1 }/*EDITMODE-END*/; function DirectionSwitcher({ value, onChange }) { const opts = [ { id: "atelier", label: "Opção 01" }, { id: "club", label: "Opção 02" }, { id: "library", label: "Opção 03" }, ]; return (
Home {opts.map((o) => { const sel = value === o.id; return ( ); })}
); } function App() { const [t, setTweak] = useTweaks(TWEAK_DEFAULTS); const [route, setRoute] = useState({ name: "home" }); // {name:'home'} | {name:'product', id} const [cart, setCart] = useState([]); const [cartOpen, setCartOpen] = useState(false); const { products, phrases } = window.UVD_DATA; // aplica tweaks ao :root useEffect(() => { document.documentElement.style.setProperty("--accent", t.accent); document.documentElement.style.setProperty("--wine", t.accent); document.documentElement.style.setProperty("--fs-scale", t.fontScale); }, [t.accent, t.fontScale]); const addToCart = (p, opts) => { const o = opts || { color: p.colors[0].name, size: p.sizes[0], qty: 1 }; const key = `${p.id}|${o.color}|${o.size}`; setCart((prev) => { const ex = prev.find((x) => x.key === key); if (ex) return prev.map((x) => x.key === key ? { ...x, qty: x.qty + o.qty } : x); return [...prev, { key, id: p.id, name: p.name, price: p.price, color: o.color, size: o.size, qty: o.qty, img: p.gallery[0].src }]; }); setCartOpen(true); }; const removeFromCart = (key) => setCart((prev) => prev.filter((x) => x.key !== key)); const openProduct = (id) => setRoute({ name: "product", id }); const goHome = () => setRoute({ name: "home" }); const onNav = (target) => { if (target === "home") { goHome(); return; } if (target === "Sobre") { goHome(); return; } // categorias → volta pra home (listagem não faz parte do escopo) goHome(); setTimeout(() => window.scrollTo({ top: window.innerHeight * 0.9, behavior: "smooth" }), 60); }; const cartCount = cart.reduce((s, i) => s + i.qty, 0); const product = route.name === "product" ? products.find((p) => p.id === route.id) : null; return (
setCartOpen(true)} onHome={goHome} onNav={onNav} menuVariant={route.name === "home" && t.homeDir === "atelier" ? "editorial" : "standard"} /> {route.name === "home" ? ( ) : ( )}
); } ReactDOM.createRoot(document.getElementById("root")).render();