(() => {
const { Button, IconButton, Badge, Tag, Icon, Card, NutrientBar, Tabs, Radio, Select, QuantityStepper, Dialog, Toast, Tooltip, Logo } = window.DotTenDesignSystem_ae7b0f;

const inr = (n) => '₹' + n.toLocaleString('en-IN');
function Shop({ add }) {
  const { plans } = window.DT;
  const [plan, setPlan] = React.useState('sub');
  const [qty, setQty] = React.useState(1);
  const price = plan === 'sub' ? plans.sub : plans.one;
  return (
    <section id="shop" style={{ maxWidth: 1200, margin: '0 auto', padding: '96px 24px 0', display: 'grid', gridTemplateColumns: 'repeat(auto-fit,minmax(min(100%,420px),1fr))', gap: 56, alignItems: 'start' }}>
      <window.Photo src="site/img/pouches-bowl.jpg" pos="center 55%" label="A bowl of DotTen Daily pouches" h={560} />
      <div>
        <div style={{ display: 'flex', gap: 8, flexWrap: 'wrap' }}><Badge tone="gold">No added sugar*</Badge><Badge tone="neutral">Vegetarian</Badge></div>
        <h2 style={{ margin: '18px 0 6px', font: '600 clamp(40px,4.4vw,56px)/1.05 var(--font-display)', letterSpacing: '-0.02em' }}>DotTen Daily</h2>
        <div style={{ font: '500 13px/1 var(--font-mono)', color: 'var(--text-3)', letterSpacing: '.04em' }}>{plans.label.toUpperCase()}</div>
        <p style={{ margin: '18px 0 24px', font: 'var(--type-body)', color: 'var(--text-2)' }}>Wholesome nourishment from whole seeds, nuts and sprouted millet, made to complement your daily balanced diet. Two DotTens a day.</p>
        <div style={{ display: 'flex', flexDirection: 'column', gap: 10 }}>
          <Radio variant="card" name="plan" value="sub" checked={plan === 'sub'} onChange={setPlan} label="Subscribe & save 15%" description="Delivered every 30 days. Skip, pause or cancel anytime." aside={inr(plans.sub)} />
          <Radio variant="card" name="plan" value="one" checked={plan === 'one'} onChange={setPlan} label="One-time purchase" aside={inr(plans.one)} />
        </div>
        <div style={{ display: 'flex', gap: 12, marginTop: 20 }}>
          <QuantityStepper value={qty} onChange={setQty} max={6} />
          <Button variant="accent" iconLeft="shopping-bag" onClick={() => add(plan, qty)} style={{ flex: 1 }}>Add to cart · {inr(price * qty)}</Button>
        </div>
        <div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fit,minmax(min(100%,200px),1fr))', gap: 12, marginTop: 24, paddingTop: 20, borderTop: '1px solid var(--border-1)' }}>
          {[['leaf', 'Ten whole-food ingredients'], ['wheat', 'Sprouted ragi'], ['package', '60 DotTens · 30 g each'], ['truck', 'Delivered across India']].map(([i, t]) => <div key={t} style={{ display: 'flex', gap: 10, alignItems: 'center', font: '400 15px/1.3 var(--font-sans)', color: 'var(--text-2)' }}><Icon name={i} size={18} color="var(--teal-800)" />{t}</div>)}
        </div>
      </div>
    </section>
  );
}
function Cart({ open, onClose, items, setItems }) {
  const total = items.reduce((s, i) => s + i.price * i.qty, 0);
  const count = items.reduce((s, i) => s + i.qty, 0);
  return (
    <Dialog open={open} onClose={onClose} placement="right" width={440} eyebrow="Your cart" title={count ? count + (count > 1 ? ' boxes' : ' box') : 'Empty for now'}
      footer={count ? <div style={{ width: '100%' }}><div style={{ display: 'flex', justifyContent: 'space-between', font: '600 17px/1 var(--font-sans)', color: 'var(--text-1)', marginBottom: 6 }}><span>Subtotal</span><span style={{ fontFamily: 'var(--font-mono)', fontWeight: 500 }}>{inr(total)}</span></div><div style={{ font: 'var(--type-caption)', color: 'var(--text-3)', marginBottom: 16 }}>Inclusive of taxes. Delivery calculated at checkout.</div><Button fullWidth size="lg" iconRight="lock">Checkout</Button></div> : null}>
      {!count ? <div style={{ padding: '16px 0' }}><p style={{ margin: '0 0 18px' }}>Your DotTens will show up here.</p><Button variant="secondary" onClick={onClose}>Keep browsing</Button></div> :
        items.map((it) => (
          <div key={it.id} style={{ display: 'grid', gridTemplateColumns: '80px 1fr', gap: 16, padding: '16px 0', borderBottom: '1px solid var(--border-1)' }}>
            <window.Photo src="site/img/pouch-kitchen.jpg" pos="center 62%" label="DotTen Daily pouch" h={80} r={4} />
            <div>
              <div style={{ display: 'flex', justifyContent: 'space-between', gap: 8 }}><span style={{ font: '600 16px/1.3 var(--font-sans)', color: 'var(--text-1)' }}>DotTen Daily</span><span style={{ font: '500 15px/1.3 var(--font-mono)', color: 'var(--text-1)' }}>{inr(it.price * it.qty)}</span></div>
              <div style={{ font: 'var(--type-caption)', color: 'var(--text-3)', margin: '2px 0 10px' }}>{it.id === 'sub' ? 'Subscription · every 30 days' : 'One-time purchase'} · 60 DotTens</div>
              <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
                <QuantityStepper size="sm" value={it.qty} max={6} onChange={(q) => setItems((c) => c.map((x) => x.id === it.id ? { ...x, qty: q } : x))} />
                <Button variant="ghost" size="sm" onClick={() => setItems((c) => c.filter((x) => x.id !== it.id))}>Remove</Button>
              </div>
            </div>
          </div>
        ))}
    </Dialog>
  );
}
Object.assign(window, { Shop, Cart, inr });
})();
