/* HomePage — editorial layout: full-bleed hero, centered statement, oxblood
   approach band with ruled columns, alternating service sections, and real
   material textures from the brand guide. */
function HomePage({ onNav }) {
  const [slide, setSlide] = React.useState(0);
  const [lightbox, setLightbox] = React.useState(null);
  /* Esc closes the enlarged image and the arrow keys step through the collage;
     the page behind is locked from scrolling while it is open. lightbox holds
     an index into `collage` so navigation stays in step with the carousel. */
  React.useEffect(() => {
    if (lightbox === null) return;
    const onKey = (e) => {
      if (e.key === 'Escape') { setLightbox(null); return; }
      if (e.key !== 'ArrowRight' && e.key !== 'ArrowLeft') return;
      e.preventDefault();
      const step = e.key === 'ArrowRight' ? 1 : -1;
      setLightbox((v) => {
        const next = (v + step + collage.length) % collage.length;
        setSlide(next);
        return next;
      });
    };
    document.addEventListener('keydown', onKey);
    const prev = document.body.style.overflow;
    document.body.style.overflow = 'hidden';
    return () => { document.removeEventListener('keydown', onKey); document.body.style.overflow = prev; };
  }, [lightbox]);
  const hoverTimer = React.useRef(null);
  React.useEffect(() => () => clearTimeout(hoverTimer.current), []);
  const collage = [
    { src: './assets/home-collage-1.jpg', alt: 'Kitchen with greige cabinetry, marble backsplash, brass pendants, and a walnut island', cap: 'Kitchen · Governor’s Mansion Historic District' },
    { src: './assets/home-collage-2.jpg', alt: 'Galley kitchen with farmhouse sink, brass fittings, and marble checkerboard floor', cap: 'Galley + scullery' },
    { src: './assets/home-collage-3.jpg', alt: 'Primary bath with black double vanity, marble top, brass fittings, and stone checkerboard floor', cap: 'Primary bath' },
    { src: './assets/home-collage-4.jpg', alt: 'Coffee bar with glass-front cabinetry, marble backsplash, copper tap, and adjoining bar pantry', cap: 'Coffee bar + pantry' },
    { src: './assets/home-collage-5.jpg', alt: 'Dining room with dark walls, antique tapestry, walnut sideboard, and olive velvet chairs', cap: 'Dining room' },
    { src: './assets/home-collage-6.jpg', alt: 'Scullery with oak cabinetry, open shelving, marble counters, and a black and white checkerboard floor', cap: 'Scullery' },
  ];

  const work = [
    { t: 'A Craftsman Reordered', p: 'Hillcrest', tone: 'oak', tag: 'Whole-home' },
    { t: 'Light Through Oak', p: 'Little Rock', tone: 'linen', tag: 'Kitchen' },
    { t: 'The Quiet Study', p: 'Heights', tone: 'walnut', tag: 'Addition' },
    { t: 'A Kitchen Opened', p: 'Maumelle', tone: 'linen', tag: 'Kitchen' },
    { t: 'The Primary Suite', p: 'Conway', tone: 'walnut', tag: 'Addition' },
    { t: 'Quapaw Quarter Restored', p: 'Little Rock', tone: 'oak', tag: 'Whole-home' },
  ];
  const { Button, Eyebrow } = window.DomumDesignSystem_84ba75;
  const { Photo, InquiryBand, Rule, SectionFrame, ScriptMark } = window;

  const approach = [
    ['Design + Build,\nA Unified Approach', 'Beautiful ideas should work beautifully in the real world. Design and construction are considered together from day one—so every layout, material, and detail is chosen with both the vision and the build in mind.'],
    ['One Point\nOf Contact', 'With design and construction management under one roof, you’re never left refereeing between designers, builders, and trades. One cohesive team carries the vision from start to finish, creating a smoother process and a more thoughtfully resolved home.'],
    ['Designed With a\nCustom Point of View', 'We believe a home can be highly functional without feeling formulaic. We design around the way you live, then layer in character, artistry, and considered details to create a home that reflects you—not a trend, a template, or everyone else.'],
    ['Designed\nBeyond Today', 'Good design should add character—not compromise value. We consider how each decision serves your home now and how it will hold up over time, balancing distinctive design with thoughtful choices that protect the long-term value of your investment.'],
  ];

  return (
    <div>
      {/* Hero — full bleed, centered */}
      <section data-hero style={{ position: 'relative', minHeight: '82vh', display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
        <div aria-hidden style={{
          position: 'absolute', inset: 0,
          background: 'url(./assets/photo-hero-home.jpg) center 55% / cover no-repeat',
        }} />
        <div style={{ position: 'absolute', inset: 0, background: 'linear-gradient(to bottom, rgba(43,33,27,.60), rgba(43,33,27,.58) 45%, rgba(43,33,27,.66))' }} />
        <div style={{ position: 'relative', textAlign: 'center', padding: '230px var(--gutter) var(--space-8)', maxWidth: '1020px' }}>
          <p style={{
            fontFamily: 'var(--font-sans)', fontSize: '12px', fontWeight: 500,
            letterSpacing: '.32em', textTransform: 'uppercase',
            color: 'var(--cream-88)', margin: '0 0 26px', lineHeight: 2,
          }}>
            Interior Design · Renovation · Build
          </p>
          <h1 style={{
            color: 'var(--ivory)', fontSize: 'clamp(2.3rem, 4.4vw, 3.7rem)',
            margin: 0, lineHeight: 1.12, fontWeight: 400,
          }}>
            Home should feel<br />anything but ordinary.
          </h1>
          <div style={{
            marginTop: 'var(--space-7)',
            display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 'var(--space-6)',
          }}>
            <Rule onDark style={{ width: '84px', background: 'var(--cream-70)' }} />
            <p style={{
              fontSize: 'var(--fs-body)', color: 'var(--ivory)', fontFamily: 'var(--font-sans)',
              lineHeight: 1.85, margin: 0, maxWidth: '62ch',
            }}>
              A home is more than a collection of beautiful choices. It's hundreds of decisions
              working together, for the way you live today and the home you'll love for years to
              come. At Spring Street, we curate the vision, direct the craftspeople, and serve as your
              Design &amp; Renovation Team from concept through completion. Not builder basic, never
              generic. Just a home that feels collected, considered, and unmistakably yours.
            </p>
            <div>
              <Button variant="primary" onClick={() => onNav('contact')}
                      style={{ background: 'var(--ivory)', color: 'var(--oxblood)', borderColor: 'var(--ivory)' }}>
                Start a Conversation
              </Button>
            </div>
          </div>
        </div>
      </section>

      {/* Approach — ruled columns */}
      <section style={{ position: 'relative', padding: 'var(--space-9) var(--gutter) 0' }}>
        <div style={{ maxWidth: '1080px', margin: '0 auto' }}>
          <p style={{
            fontFamily: 'var(--font-sans)', fontSize: '12px', fontWeight: 500,
            letterSpacing: '.32em', textTransform: 'uppercase', color: 'var(--text-muted)',
            textAlign: 'center', margin: '0 0 20px', lineHeight: 2,
          }}>
            Curated. Crafted. Considered
          </p>
          <h2 style={{
            fontSize: 'clamp(1.9rem, 3.4vw, 2.6rem)',
            margin: '0 0 var(--space-8)', textAlign: 'center', fontWeight: 400,
          }}>
            The Spring Street Approach
          </h2>
          <div style={{ display: 'grid', gridTemplateColumns: 'repeat(4, minmax(0, 1fr))', gap: '36px' }}>
            {approach.map(([t, d]) => (
              <div key={t} style={{ textAlign: 'center', display: 'flex', flexDirection: 'column', height: '100%' }}>
                <Rule />
                <h3 style={{
                  fontSize: '1.2rem', fontWeight: 400,
                  margin: '22px 0 18px', lineHeight: 1.45, whiteSpace: 'pre-line',
                  minHeight: 'calc(1.45em * 3)',
                }}>{t}</h3>
                <p style={{
                  color: 'var(--text-secondary)', fontSize: 'var(--fs-caption)',
                  lineHeight: 1.85, margin: '0 0 22px',
                }}>{d}</p>
                <div style={{ marginTop: 'auto' }}><Rule /></div>
              </div>
            ))}
          </div>
        </div>
      </section>

      {/* Selected work */}
      <section style={{ padding: 'var(--space-8) var(--gutter) var(--space-9)' }}>
        <div style={{ maxWidth: 'var(--page-max)', margin: '0 auto' }}>
          <div style={{ textAlign: 'center', marginBottom: 'var(--space-8)' }}>
            <Eyebrow>Selected Work</Eyebrow>
            <h2 style={{ fontSize: 'clamp(1.8rem, 3.2vw, 2.4rem)', margin: '18px 0 0', fontWeight: 400 }}>
              Spaces by Spring Street
            </h2>
          </div>
          <div style={{ position: 'relative', height: 'clamp(380px, 52vw, 620px)', margin: '0 calc(50% - 50vw) var(--space-7)', width: '100vw', overflow: 'hidden' }}>
            {collage.map((im, i) => {
              const n = collage.length;
              let d = i - slide;
              if (d > n / 2) d -= n;
              if (d < -n / 2) d += n;
              const near = Math.abs(d) <= 2;
              return (
                <button key={im.src} type="button" tabIndex={d === 0 ? 0 : -1} aria-hidden={d !== 0}
                  onClick={() => (d === 0 ? setLightbox(i) : setSlide(i))}
                  onMouseEnter={() => {
                    if (d === 0) return;
                    clearTimeout(hoverTimer.current);
                    hoverTimer.current = setTimeout(() => setSlide(i), 420);
                  }}
                  onMouseLeave={() => clearTimeout(hoverTimer.current)}
                  aria-label={d === 0 ? `Enlarge ${im.cap}` : `Show ${im.cap}`}
                  style={{
                    position: 'absolute', top: '50%', left: '50%', width: 'clamp(240px, 34vw, 400px)',
                    transform: `translate(-50%, -50%) translateX(${d * 100}%) scale(${d === 0 ? 1 : 0.78})`,
                    opacity: near ? (d === 0 ? 1 : Math.abs(d) === 1 ? 0.55 : 0.32) : 0,
                    pointerEvents: near ? 'auto' : 'none', zIndex: d === 0 ? 2 : 1,
                    transition: 'transform 760ms var(--ease-quiet), opacity 760ms var(--ease-quiet)',
                    padding: 0, border: 'none', background: 'transparent', cursor: d === 0 ? 'zoom-in' : 'pointer', textAlign: 'center',
                  }}>
                  <img src={im.src} alt={im.alt} loading="lazy" style={{ width: '100%', display: 'block', aspectRatio: '3 / 4', objectFit: 'cover' }} />
                </button>
              );
            })}
          </div>
          <div style={{ display: 'flex', justifyContent: 'center', marginTop: 'var(--space-6)' }}>
            <Button variant="secondary" onClick={() => onNav('portfolio')}>View Portfolio</Button>
          </div>
        </div>
      </section>

      <InquiryBand />

      {/* Lightbox — the centred work image enlarges in place rather than navigating away. */}
      {lightbox !== null && (
        <div role="dialog" aria-modal="true" onClick={() => setLightbox(null)}
             style={{
               position: 'fixed', inset: 0, zIndex: 80,
               background: 'rgba(28,12,14,.88)',
               display: 'flex', alignItems: 'center', justifyContent: 'center',
               padding: 'var(--space-7)', cursor: 'zoom-out',
             }}>
          <button type="button" onClick={() => setLightbox(null)} aria-label="Close enlarged image"
                  style={{
                    position: 'absolute', top: '22px', right: '22px', zIndex: 2,
                    display: 'flex', alignItems: 'center', gap: '10px',
                    background: 'rgba(28,12,14,.55)', border: '1px solid var(--cream-70)', borderRadius: 0,
                    padding: '11px 18px', cursor: 'pointer',
                    fontFamily: 'var(--font-sans)', fontSize: '11px', fontWeight: 500,
                    letterSpacing: '.22em', textTransform: 'uppercase', color: 'var(--ivory)',
                  }}>
            <span aria-hidden style={{ position: 'relative', width: '12px', height: '12px', display: 'inline-block' }}>
              <span style={{ position: 'absolute', top: '5px', left: 0, width: '12px', height: '1px', background: 'var(--ivory)', transform: 'rotate(45deg)' }}></span>
              <span style={{ position: 'absolute', top: '5px', left: 0, width: '12px', height: '1px', background: 'var(--ivory)', transform: 'rotate(-45deg)' }}></span>
            </span>
            Close
          </button>
          {/* Prev / next arrows — the same steps the keyboard arrows take. */}
          {[-1, 1].map((step) => (
            <button key={step} type="button"
                    onClick={(e) => { e.stopPropagation(); const next = (lightbox + step + collage.length) % collage.length; setLightbox(next); setSlide(next); }}
                    aria-label={step === 1 ? 'Next image' : 'Previous image'}
                    style={{
                      position: 'absolute', top: '50%', transform: 'translateY(-50%)',
                      [step === 1 ? 'right' : 'left']: 'clamp(12px, 3vw, 40px)', zIndex: 2,
                      width: '52px', height: '52px', display: 'flex', alignItems: 'center', justifyContent: 'center',
                      background: 'rgba(28,12,14,.55)', border: '1px solid var(--cream-70)', borderRadius: 0,
                      cursor: 'pointer',
                    }}>
              <span aria-hidden style={{
                width: '13px', height: '13px', display: 'block',
                borderTop: '1px solid var(--ivory)',
                [step === 1 ? 'borderRight' : 'borderLeft']: '1px solid var(--ivory)',
                transform: step === 1 ? 'rotate(45deg) translate(-2px, 2px)' : 'rotate(-45deg) translate(2px, 2px)',
              }}></span>
            </button>
          ))}
          <img src={collage[lightbox].src} alt={collage[lightbox].alt || ''}
               onClick={(e) => e.stopPropagation()}
               style={{ maxWidth: 'min(92vw, 1100px)', maxHeight: '86vh', width: 'auto', height: 'auto', display: 'block', cursor: 'default' }} />
          <p style={{
            position: 'absolute', bottom: '22px', left: 0, right: 0, textAlign: 'center', margin: 0,
            fontFamily: 'var(--font-sans)', fontSize: '11px', fontWeight: 500,
            letterSpacing: '.22em', textTransform: 'uppercase', color: 'var(--cream-70)',
          }}>{lightbox + 1} / {collage.length}</p>
        </div>
      )}
    </div>
  );
}
window.HomePage = HomePage;
