/* global React, ReactDOM, Icon, Button, Badge, ToastHost, BotFlow,
DtHome, DtCatalog, DtProduct, DtCart, DtCheckout, DtServices, DtWholesale,
ChromeWindow, useState, useEffect */
function DtHeader({ route, go, cartCount }) {
const nav = [["catalog", "Productos"], ["services", "Servicios"], ["mayorista", "Mayorista"]];
return (
);
}
function DtFooter({ go }) {
const NOGO = window.NOGO;
return (
);
}
function DtApp({ scale = 1 }) {
const NOGO = window.NOGO;
const [stack, setStack] = useState(["home"]);
const route = stack[stack.length - 1];
const [product, setProduct] = useState(null);
const [cart, setCart] = useState([]);
const [filters, setFilters] = useState({ use: null, colorFam: null });
const [bot, setBot] = useState(null);
const [toasts, setToasts] = useState([]);
const scrollRef = React.useRef(null);
const go = (to) => {
if (to === route && to !== "catalog") return;
setStack((s) => [...s, to]);
if (scrollRef.current) scrollRef.current.scrollTop = 0;
};
const openProduct = (p) => { setProduct(p); setStack((s) => [...s, "product"]); if (scrollRef.current) scrollRef.current.scrollTop = 0; };
const addToast = (msg, opts = {}) => {
const id = Date.now() + Math.random();
setToasts((t) => [...t, { id, msg, ...opts }]);
setTimeout(() => setToasts((t) => t.filter((x) => x.id !== id)), 2600);
};
const cartCount = cart.reduce((n, i) => n + i.qty, 0);
const onAdd = ({ product, presId, color }) => setBot({ product, presId, color });
const startAdvisor = () => {
const product = NOGO.products.find((p) => p.featured) || NOGO.products[0];
const presId = product.pres[Math.min(1, product.pres.length - 1)];
const fam = product.colors[0];
const color = NOGO.palette[fam][2] || NOGO.palette[fam][0];
setBot({ product, presId, color });
};
useEffect(() => {
if (window.NOGO_DEPLOY_MODE && window.location.hash === "#asesor") {
startAdvisor();
}
}, []);
const onBotConfirm = (items) => {
setCart((prev) => {
const next = [...prev];
items.forEach((it) => {
const k = next.findIndex((x) => x.productId === it.productId && x.presId === it.presId && (x.color?.hex || null) === (it.color?.hex || null));
if (k >= 0) next[k] = { ...next[k], qty: next[k].qty + it.qty };
else next.push(it);
});
return next;
});
setBot(null);
addToast("Agregado al carrito", { tone: "success", icon: "check" });
};
const setQty = (idx, q) => setCart((c) => c.map((it, i) => (i === idx ? { ...it, qty: q } : it)));
const removeItem = (idx) => setCart((c) => c.filter((_, i) => i !== idx));
const onPlace = () => { setStack((s) => [...s, "confirm"]); setTimeout(() => setCart([]), 400); };
return (
{route === "home" &&
}
{route === "catalog" &&
}
{route === "product" && product &&
}
{route === "cart" &&
}
{route === "checkout" &&
}
{route === "services" &&
}
{route === "mayorista" &&
}
{route === "confirm" &&
}
{bot && ReactDOM.createPortal(
{ if (e.target.classList.contains("dt-modal-overlay")) setBot(null); }}>
setBot(null)} />
,
document.body
)}
{toasts.length > 0 && ReactDOM.createPortal(
{toasts.map((t) =>
{t.msg}
)}
,
document.body
)}
);
}
function DtConfirm({ go }) {
return (
¡Gracias por tu compra!
Te enviamos el comprobante por email. Podés seguir tu pedido desde Mi cuenta.
N° de pedido#NGP-{Math.floor(1000 + Math.random() * 9000)}
);
}
/* Montaje con escalado dentro del marco de navegador */
function Root() {
const [scale, setScale] = useState(1);
const W = 1280, H = 820;
useEffect(() => {
const fit = () => setScale(Math.min(1, (window.innerWidth - 48) / W, (window.innerHeight - 48) / H));
fit(); window.addEventListener("resize", fit); return () => window.removeEventListener("resize", fit);
}, []);
return (
);
}
Object.assign(window, { DtApp, DtHeader, DtFooter });
if (!window.NOGO_SKIP_AUTOMOUNT) {
ReactDOM.createRoot(document.getElementById("root")).render();
}