// Maple Pavers — DESKTOP sections, part 2: Gallery, Why, Social, Testimonials, CTA, Footer.
(function () {
  const DS = window.MaplePaversDesignSystem_8de4d8;
  const { Button, Badge, StatBlock } = DS;
  const { Icon, Overline, Stars, PHOTO, ASSET, PHONE, startQuote } = window.MP;
  const D = window.MP.data;
  const MPD = window.MPD;
  const { Container, SecHead } = MPD;
  const BEFORE = 'grayscale(0.9) brightness(0.62) contrast(0.92)';

  // ───────────────────────── Gallery (before/after slider) ─────────────────────────
  // Accepts a gallery `item`. Uses real `before` + `after` images when present;
  // falls back to grayscale-on-after fake when only `img` is set (legacy items).
  function BASlider({ item, height }) {
    const [pos, setPos] = React.useState(52);
    const ref = React.useRef(null);
    const beforeImg = item.before || item.img;
    const afterImg = item.after || item.img;
    const beforeFilter = item.before ? 'none' : BEFORE;
    const set = (cx) => { const r = ref.current.getBoundingClientRect(); setPos(Math.max(2, Math.min(98, ((cx - r.left) / r.width) * 100))); };
    const down = (e) => {
      e.preventDefault();
      const move = (ev) => set(ev.touches ? ev.touches[0].clientX : ev.clientX);
      move(e.nativeEvent);
      const up = () => { window.removeEventListener('pointermove', move); window.removeEventListener('pointerup', up); };
      window.addEventListener('pointermove', move); window.addEventListener('pointerup', up);
    };
    return (
      <div className="mp-ba" ref={ref} style={{ height, borderRadius: 'var(--radius-lg)', boxShadow: 'var(--shadow)' }} onPointerDown={down}>
        <div style={{ position: 'absolute', inset: 0, backgroundImage: `url(${PHOTO}${beforeImg})`, backgroundSize: 'cover', backgroundPosition: 'center', filter: beforeFilter }} />
        <span style={{ position: 'absolute', top: 16, left: 16, zIndex: 3 }}><Badge variant="on-dark">Before</Badge></span>
        <div className="mp-ba-after" style={{ clipPath: `inset(0 ${100 - pos}% 0 0)` }}>
          <div style={{ position: 'absolute', inset: 0, backgroundImage: `url(${PHOTO}${afterImg})`, backgroundSize: 'cover', backgroundPosition: 'center' }} />
          <span style={{ position: 'absolute', top: 16, right: 16 }}><Badge variant="solid">After</Badge></span>
        </div>
        <div className="mp-ba-handle" style={{ left: `${pos}%` }}><div className="mp-ba-knob"><Icon name="move-h" size={24} /></div></div>
      </div>
    );
  }
  function Gallery() {
    const items = D.gallery.slice(0, 5);
    const [active, setActive] = React.useState(0);
    return (
      <section id="gallery" style={{ background: 'var(--color-bg)', padding: '96px 0' }}>
        <Container>
          <SecHead over="Recent Work" title="See what we've built." desc="Drag to reveal the transformation. No staged stock — actual driveways we tore out and rebuilt." />
          <div style={{ marginTop: 52 }}>
            <BASlider item={items[active]} height={520} />
            <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', marginTop: 18 }}>
              <div style={{ fontFamily: 'var(--font-display)', fontWeight: 600, fontSize: 20, color: 'var(--text-strong)' }}>{items[active].title} <span style={{ fontFamily: 'var(--font-body)', fontSize: 14, color: 'var(--text-muted)', fontWeight: 400 }}>· {items[active].cat}</span></div>
              <div style={{ display: 'flex', gap: 10 }}>
                {items.map((it, i) => (
                  <button key={it.title} onClick={() => setActive(i)} aria-label={it.title} style={{ width: 92, height: 64, padding: 0, border: i === active ? '2px solid var(--terracotta)' : '1px solid var(--border-default)', borderRadius: 'var(--radius)', overflow: 'hidden', cursor: 'pointer', background: `center/cover url(${PHOTO}${it.img})` }} />
                ))}
              </div>
            </div>
          </div>
        </Container>
      </section>
    );
  }
  MPD.Gallery = Gallery;

  // ───────────────────────── Why (dark pillars) ─────────────────────────
  function Why() {
    return (
      <section id="why" style={{ background: 'var(--graphite)', padding: '96px 0' }}>
        <Container>
          <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 64, alignItems: 'center', marginBottom: 56 }}>
            <SecHead align="left" onDark over="Why Maple Pavers" title="We earn it. We don't claim it." />
            <p style={{ fontFamily: 'var(--font-body)', fontSize: 17, lineHeight: '28px', color: 'var(--text-on-dark-muted)', margin: 0 }}>
              Three decades of high-end stonework across Toronto and the GTA. We're not the cheapest quote you'll get — we're the one you won't have to call back.
            </p>
          </div>
          <div style={{ display: 'grid', gridTemplateColumns: 'repeat(3,1fr)', gap: 24 }}>
            {D.pillars.map((p) => (
              <div key={p.t} style={{ background: 'var(--graphite-800)', border: '1px solid var(--border-on-dark)', borderRadius: 'var(--radius-lg)', padding: 30 }}>
                <div style={{ width: 54, height: 54, borderRadius: 'var(--radius)', background: 'rgba(196,122,90,0.16)', display: 'flex', alignItems: 'center', justifyContent: 'center', marginBottom: 18 }}>
                  <Icon name={p.icon} size={26} color="var(--clay)" />
                </div>
                <h3 style={{ fontFamily: 'var(--font-display)', fontWeight: 600, fontSize: 22, color: 'var(--beige-150)', margin: '0 0 10px' }}>{p.t}</h3>
                <p style={{ fontFamily: 'var(--font-body)', fontSize: 15, lineHeight: '24px', color: 'var(--text-on-dark-muted)', margin: 0 }}>{p.d}</p>
              </div>
            ))}
          </div>
        </Container>
      </section>
    );
  }
  MPD.Why = Why;

  // ───────────────────────── Social proof (marquee) ─────────────────────────
  function Social() {
    const loop = [...D.badges, ...D.badges, ...D.badges];
    return (
      <section style={{ background: 'var(--color-bg)', padding: '72px 0', borderBottom: '1px solid var(--border-subtle)' }}>
        <div style={{ textAlign: 'center', marginBottom: 30 }}>
          <h2 style={{ fontFamily: 'var(--font-display)', fontWeight: 600, fontSize: 28, color: 'var(--text-strong)', margin: 0 }}>Trusted across the GTA</h2>
        </div>
        <div className="mp-marq-mask">
          <div style={{ display: 'flex', gap: 16, width: 'max-content', animation: 'mpMarq 26s linear infinite' }}>
            {loop.map((b, i) => (
              <span key={i} style={{ display: 'flex', alignItems: 'center', gap: 11, background: 'var(--color-surface)', border: '1px solid var(--border-subtle)', borderRadius: 'var(--radius)', padding: '16px 24px', whiteSpace: 'nowrap', boxShadow: 'var(--shadow-sm)' }}>
                <Icon name={b.icon} size={22} color="var(--terracotta)" />
                <span style={{ fontFamily: 'var(--font-body)', fontWeight: 700, fontSize: 15, color: 'var(--text-strong)' }}>{b.t}</span>
                <span style={{ fontFamily: 'var(--font-body)', fontSize: 13, color: 'var(--text-muted)' }}>{b.s}</span>
              </span>
            ))}
          </div>
        </div>
        <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 40, marginTop: 36 }}>
          {D.partners.map((p) => <span key={p} style={{ fontFamily: 'var(--font-display)', fontWeight: 700, fontSize: 20, color: 'var(--text-strong)', opacity: 0.65 }}>{p}</span>)}
        </div>
      </section>
    );
  }
  MPD.Social = Social;

  // ───────────────────────── Testimonials (marquee) ─────────────────────────
  function Testimonials() {
    const loop = [...D.testimonials, ...D.testimonials];
    return (
      <section id="reviews" style={{ background: 'var(--beige-300)', padding: '96px 0' }}>
        <Container><SecHead over="Homeowner Reviews" title="From the homeowners who hired us." /></Container>
        <div className="mp-marq-mask" style={{ marginTop: 52 }}>
          <div style={{ display: 'flex', gap: 22, width: 'max-content', animation: 'mpMarq 44s linear infinite', alignItems: 'stretch' }}>
            {loop.map((t, i) => (
              <figure key={i} style={{ margin: 0, width: 380, background: 'var(--color-surface)', border: '1px solid var(--border-subtle)', borderRadius: 'var(--radius-lg)', boxShadow: 'var(--shadow-sm)', padding: '26px 28px', display: 'flex', flexDirection: 'column', gap: 14 }}>
                <Stars count={5} size={16} />
                <blockquote style={{ margin: 0, fontFamily: 'var(--font-body)', fontSize: 15.5, lineHeight: '25px', color: 'var(--text-body)' }}>&ldquo;{t.quote}&rdquo;</blockquote>
                <figcaption><span style={{ fontFamily: 'var(--font-body)', fontWeight: 700, fontSize: 14, color: 'var(--text-strong)', display: 'block' }}>&mdash; {t.author}</span><span style={{ fontFamily: 'var(--font-body)', fontSize: 12.5, color: 'var(--text-muted)' }}>{t.location}</span></figcaption>
              </figure>
            ))}
          </div>
        </div>
      </section>
    );
  }
  MPD.Testimonials = Testimonials;

  // ───────────────────────── CTA (dark, render-only) ─────────────────────────
  function CTA() {
    return (
      <section style={{ background: '#141414', padding: '96px 0' }}>
        <Container style={{ textAlign: 'center' }}>
          <Overline onDark color="var(--clay)">Free · No Obligation</Overline>
          <h2 style={{ fontFamily: 'var(--font-display)', fontWeight: 600, fontSize: 'clamp(34px,4vw,52px)', lineHeight: 1.08, color: 'var(--beige-150)', margin: '14px auto 0', maxWidth: 760 }}>Ready to lose the cracked asphalt?</h2>
          <p style={{ fontFamily: 'var(--font-body)', fontSize: 18, lineHeight: '28px', color: 'var(--text-on-dark-muted)', margin: '18px auto 30px', maxWidth: 520 }}>
            See your home redone in a premium paver finish — free, in 90 seconds. The hardest part is uploading a photo.
          </p>
          <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 16 }}>
            <Button variant="primary" size="lg" withArrow onClick={startQuote}>Design My Driveway</Button>
            <a href="tel:+16472428442" style={{ display: 'inline-flex', alignItems: 'center', gap: 9, padding: '18px 26px', borderRadius: 'var(--radius)', border: '1px solid rgba(248,240,229,0.4)', color: 'var(--beige-150)', fontFamily: 'var(--font-body)', fontWeight: 700, fontSize: 15, letterSpacing: '0.1em', textTransform: 'uppercase', textDecoration: 'none' }}>
              <Icon name="phone" size={17} color="var(--clay)" /> {PHONE}
            </a>
          </div>
        </Container>
      </section>
    );
  }
  MPD.CTA = CTA;

  // ───────────────────────── Footer (full) ─────────────────────────
  function Footer() {
    const ADDRESS = '245 Bridgeland Ave, North York, ON M6A 1Z4';
    const EMAIL = 'hello@maplepavers.ca';
    const HOURS = 'Mon–Fri 8 AM–6 PM · Sat by appointment';
    const lbl = { fontFamily: 'var(--font-body)', fontWeight: 700, fontSize: 12, letterSpacing: '0.12em', textTransform: 'uppercase', color: 'var(--clay)', margin: '0 0 16px' };
    const li = { fontFamily: 'var(--font-body)', fontSize: 14, lineHeight: '26px', color: 'var(--text-on-dark-muted)', textDecoration: 'none', display: 'block' };
    return (
      <footer style={{ background: 'var(--graphite)', color: 'var(--beige-150)' }}>
        <Container style={{ padding: '64px 48px 0' }}>
          <div style={{ display: 'grid', gridTemplateColumns: '1.5fr 1fr 1fr 1.4fr', gap: 48 }}>
            <div>
              <img src={ASSET + 'logo-horizontal-dark.png'} alt="Maple Pavers" style={{ height: 38, marginBottom: 18 }} />
              <p style={{ fontFamily: 'var(--font-body)', fontSize: 14, lineHeight: '23px', color: 'var(--text-on-dark-muted)', margin: '0 0 18px', maxWidth: 300 }}>Timeless stonework. Toronto trusted. Built to last. Family-owned since 1992.</p>
              <div style={{ display: 'flex', gap: 10 }}>
                {['instagram', 'facebook'].map((n) => <a key={n} href="#" aria-label={n} style={{ width: 38, height: 38, borderRadius: 'var(--radius)', border: '1px solid rgba(248,240,229,0.22)', display: 'flex', alignItems: 'center', justifyContent: 'center', color: 'var(--beige-150)' }}><Icon name={n} size={17} /></a>)}
              </div>
            </div>
            <div>
              <p style={lbl}>Explore</p>
              {[['Process', '#process'], ['Services', '#services'], ['Gallery', '#gallery'], ['Why Us', '#why'], ['Reviews', '#reviews']].map(([t, h]) => <a key={t} href={h} style={li}>{t}</a>)}
            </div>
            <div>
              <p style={lbl}>Services</p>
              {D.services.map((s) => <a key={s.t} href="#services" style={li}>{s.t}</a>)}
            </div>
            <div>
              <p style={lbl}>Get in Touch</p>
              <a href="tel:+16472428442" style={{ ...li, display: 'flex', alignItems: 'center', gap: 9 }}><Icon name="phone" size={15} color="var(--clay)" /> {PHONE}</a>
              <a href={'mailto:' + EMAIL} style={{ ...li, display: 'flex', alignItems: 'center', gap: 9 }}><Icon name="mail" size={15} color="var(--clay)" /> {EMAIL}</a>
              <span style={{ ...li, display: 'flex', alignItems: 'flex-start', gap: 9 }}><Icon name="map-pin" size={15} color="var(--clay)" style={{ marginTop: 5, flex: 'none' }} /> {ADDRESS}</span>
              <span style={{ ...li, display: 'flex', alignItems: 'center', gap: 9 }}><Icon name="clock" size={15} color="var(--clay)" /> {HOURS}</span>
            </div>
          </div>
          <div style={{ marginTop: 40, paddingTop: 22, paddingBottom: 28, borderTop: '1px solid rgba(255,255,255,0.12)', display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
            <span style={{ fontFamily: 'var(--font-body)', fontSize: 12, color: 'var(--text-on-dark-muted)' }}>© 2025 Maple Pavers Inc. · Serving Toronto &amp; the GTA</span>
            <div style={{ display: 'flex', gap: 18, fontFamily: 'var(--font-body)', fontSize: 12 }}>
              <a href="#" style={{ color: 'var(--text-on-dark-muted)' }}>Privacy</a>
              <a href="#" style={{ color: 'var(--text-on-dark-muted)' }}>Terms</a>
            </div>
          </div>
        </Container>
      </footer>
    );
  }
  MPD.Footer = Footer;
})();
