// App shell — routing, cart state, slide-in cart drawer function App() { const { Icon, Header, Footer, HomeScreen, ShopScreen, ProductScreen, AboutScreen, QualityScreen, EspaceProScreen } = window; const { Button } = window.SinopharmaDesignSystem_d11735; const [route, setRoute] = React.useState('home'); const [current, setCurrent] = React.useState(null); const [cart, setCart] = React.useState([]); const [drawer, setDrawer] = React.useState(false); const [isMobile, setIsMobile] = React.useState(window.innerWidth < 760); React.useEffect(() => { const onResize = () => setIsMobile(window.innerWidth < 760); window.addEventListener('resize', onResize); return () => window.removeEventListener('resize', onResize); }, []); const nav = (r) => { setRoute(r); window.scrollTo(0, 0); }; const open = (p) => { setCurrent(p); setRoute('product'); window.scrollTo(0, 0); }; const add = (p, qty = 1) => { setCart((c) => { const ex = c.find((i) => i.id === p.id); if (ex) return c.map((i) => i.id === p.id ? { ...i, qty: i.qty + qty } : i); return [...c, { ...p, qty }]; }); setDrawer(true); }; const remove = (id) => setCart((c) => c.filter((i) => i.id !== id)); const count = cart.reduce((n, i) => n + i.qty, 0); const total = cart.reduce((n, i) => n + parseFloat(i.price.replace(',', '.')) * i.qty, 0); return (
setDrawer(true)} active={route} mobile={isMobile} /> {route === 'home' && } {route === 'shop' && } {route === 'about' && } {route === 'quality' && } {route === 'pro' && } {route === 'product' && current && }