/* ============================================================
   HOME — hero · value strip · category grid · featured
   ============================================================ */
function HomeHero() {
  const { nav } = useStore();
  const H = BB.BRAND.hero;
  const { clips } = BB.IMG.hero;
  return (
    <section style={{ background: 'var(--cream)', borderBottom: '1px solid var(--line)' }}>
      <div className="container wide hero-split" style={{ display: 'grid', gridTemplateColumns: '1.05fr .95fr', gap: 'clamp(32px,5vw,72px)', alignItems: 'center', padding: 'clamp(48px,7vw,96px) var(--gutter)' }}>
        <div>
          <h1 className="display" style={{ margin: '0 0 30px', animation: 'rise .7s .05s both' }}>
            {H.titleA}<br /><em style={{ color: 'var(--gold-deep)' }}>Sourced ethically.</em>
          </h1>
          <p style={{ fontSize: 17, color: 'var(--ink-soft)', maxWidth: 460, lineHeight: 1.6, marginBottom: 26, animation: 'rise .7s .1s both' }}>Genuine Converse and Vans, sourced and sold in original condition from Lagos.</p>
          <div style={{ display: 'flex', gap: 12, flexWrap: 'wrap', animation: 'rise .7s .2s both' }}>
            <button className="btn btn-gold btn-lg" onClick={() => nav(H.cta.page)}>Shop →</button>
          </div>
        </div>
        <div className="hero-collage" style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 12, animation: 'rise .8s .2s both' }}>
          {clips.map((c, i) => (
            <div key={'c' + i} className="hero-panel" style={{ position: 'relative', borderRadius: 'var(--r-lg)', overflow: 'hidden', boxShadow: 'var(--shadow-sm)', transition: 'transform .45s cubic-bezier(.2,.8,.2,1), box-shadow .45s' }}>
              <HeroPanel poster={c.poster} video={c.video} label={c.label} style={{ aspectRatio: '4/3.4' }} />
            </div>
          ))}
        </div>
      </div>
    </section>
  );
}

function ValueStrip() {
  const items = [
    [I.truck, 'Nationwide delivery', 'Every state, tracked door-to-door'],
    [I.shield, 'Secure checkout', 'Card, transfer — encrypted end to end'],
    [I.globe, 'Secure payment', 'Pay in ₦ or $ — card, transfer, or wire'],
    [I.box, 'Live order tracking', 'From confirmed to delivered'],
  ];
  return (
    <section style={{ borderBottom: '1px solid var(--line)', background: 'var(--ivory)' }}>
      <div className="container wide value-strip" style={{ display: 'grid', gridTemplateColumns: 'repeat(4, 1fr)', gap: 24, padding: '30px var(--gutter)' }}>
        {items.map(([Icon, t, s], i) =>
        <div key={i} style={{ display: 'flex', gap: 13, alignItems: 'center' }}>
            <span style={{ width: 44, height: 44, flexShrink: 0, borderRadius: 'var(--r-md)', background: 'var(--gold-soft)', display: 'grid', placeItems: 'center', color: 'var(--gold-deep)' }}>{Icon({ width: 21, height: 21 })}</span>
            <div style={{ lineHeight: 1.25 }}><div style={{ fontWeight: 600, fontSize: 14 }}>{t}</div><div style={{ fontSize: 12.5, color: 'var(--ink-soft)', marginTop: 2 }}>{s}</div></div>
          </div>
        )}
      </div>
    </section>);
}

/* ── Category grid — Converse / Vans ── */
function CategoryGrid() {
  const { nav } = useStore();
  const converse = BB.products.filter(p => p.subtype === 'converse');
  const vans = BB.products.filter(p => p.subtype === 'vans');

  const Tile = ({ name, cta, onClick, img, variant, minHeight }) => (
    <Reveal className="cat-tile cat-feature" onClick={onClick} style={{ cursor: 'pointer' }}>
      <Ph src={img} label={name} variant={variant} style={{ height: '100%', minHeight, borderRadius: 'var(--r-lg)' }} />
      <div style={{ position: 'absolute', inset: 0, borderRadius: 'var(--r-lg)', background: 'linear-gradient(to top, rgba(23,17,9,.85) 0%, rgba(23,17,9,.42) 45%, transparent 70%)', display: 'flex', flexDirection: 'column', justifyContent: 'flex-end', padding: 22, color: 'var(--cream)' }}>
        <h3 style={{ fontSize: 27, color: '#FFFDF8' }}>{name}</h3>
        <span style={{ display: 'inline-flex', alignItems: 'center', gap: 7, fontSize: 12, letterSpacing: '.1em', textTransform: 'uppercase', marginTop: 10, color: 'var(--gold-soft)', fontWeight: 600 }}>{cta} <I.arrow width={15} height={15} /></span>
      </div>
    </Reveal>
  );

  return (
    <section className="container wide" style={{ padding: 'clamp(60px,8vw,110px) var(--gutter)' }}>
      <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-end', flexWrap: 'wrap', gap: 16, marginBottom: 38 }}>
        <div>
          <h2 style={{ fontSize: 'clamp(32px,4.5vw,54px)' }}>Converse and Vans,<br />sourced right.</h2>
        </div>
        <button className="link-u" style={{ fontSize: 14, fontWeight: 600 }} onClick={() => nav('shop')}>View all products →</button>
      </div>
      <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 16 }}>
        <Tile name="Converse" cta={`${converse.length} pieces`} minHeight={340}
          variant="ph-gold" img={converse[0]?.img} onClick={() => nav('shop', { q: 'Converse' })} />
        <Tile name="Vans" cta={`${vans.length} pieces`} minHeight={340}
          variant="ph-sage" img={vans[0]?.img} onClick={() => nav('shop', { q: 'Vans' })} />
      </div>
    </section>);
}

function Featured() {
  const { nav } = useStore();
  const [tab, setTab] = useState('best');
  const list = BB.products.filter((p) => tab === 'best' ? p.tags.includes('best') : p.tags.includes('new')).slice(0, 8);
  return (
    <section style={{ background: 'var(--ivory)', borderTop: '1px solid var(--line)', borderBottom: '1px solid var(--line)' }}>
      <div className="container wide" style={{ padding: 'clamp(60px,8vw,110px) var(--gutter)' }}>
        <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-end', flexWrap: 'wrap', gap: 18, marginBottom: 38 }}>
          <div>
            <h2 style={{ fontSize: 'clamp(32px,4.5vw,54px)' }}>Shop the collection</h2>
          </div>
          <div style={{ display: 'flex', gap: 8 }}>
            <button className={`chip ${tab === 'best' ? 'active' : ''}`} onClick={() => setTab('best')}>Bestsellers</button>
            <button className={`chip ${tab === 'new' ? 'active' : ''}`} onClick={() => setTab('new')}>New in</button>
          </div>
        </div>
        <div className="prod-grid">
          {list.map((p, i) => <ProductCard key={p.id} p={p} delay={i % 4 + 1} />)}
        </div>
        <div style={{ textAlign: 'center', marginTop: 44 }}>
          <button className="btn btn-outline btn-lg" onClick={() => nav('shop')}>Shop everything</button>
        </div>
      </div>
    </section>);
}

/* ── Custom orders teaser ─────────────────────────────────── */
function HomePage() {
  return (
    <>
      <HomeHero />
      <ValueStrip />
      <CategoryGrid />
      <Featured />
      <Newsletter />
    </>);
}

Object.assign(window, { HomePage });
