/* AKMBD Website — Hero (quiet direction: full-bleed dark, image-forward,
   minimal text bottom-left over a crossfading photo rotation).
   heroMedia tweak: 'photo' | 'sketch' (line-art motif) | 'minimal' (type only). */

function Watermark({ opacity = 0.06 }) {
  const rows = Array.from({ length: 8 });
  return (
    <div aria-hidden="true" style={{ position:'absolute', inset:0, display:'flex', flexDirection:'column',
      justifyContent:'center', pointerEvents:'none', opacity, overflow:'hidden' }}>
      {rows.map((_, i) => (
        <div key={i} style={{ fontFamily:'var(--font-display)', fontWeight:400, fontSize:'7.6vw', lineHeight:1.05,
          letterSpacing:'0.02em', whiteSpace:'nowrap', color:'#fff', textTransform:'uppercase',
          transform: i%2 ? 'translateX(-6%)':'translateX(3%)' }}>
          Build&nbsp;Design&nbsp;Build&nbsp;Design&nbsp;Build&nbsp;Design
        </div>
      ))}
    </div>
  );
}

/* crossfading rotation of full-bleed hero photographs.
   Each photo sits stacked + absolutely positioned; only the active one is opaque.
   Reduced-motion: holds on the first frame (no rotation). */
const HERO_PHOTOS = [
  { id:'heroPasadena',  src:'assets/hero-pasadena.jpg',   pos:'center 62%' },
  { id:'heroInterior',  src:'assets/hero-interior.jpg',   pos:'center 50%' },
  { id:'heroLazooSk',   src:'assets/hero-lazoo-sketch.jpg', pos:'center 50%' },
  { id:'heroLazoo',     src:'assets/hero-lazoo.jpg',      pos:'center 64%' },
];
function HeroPhotos({ interval = 6000 }) {
  const [i, setI] = React.useState(0);
  React.useEffect(() => {
    const reduce = window.matchMedia && window.matchMedia('(prefers-reduced-motion: reduce)').matches;
    if (reduce || HERO_PHOTOS.length < 2) return;
    const t = setInterval(() => setI(p => (p + 1) % HERO_PHOTOS.length), interval);
    return () => clearInterval(t);
  }, [interval]);
  return (
    <React.Fragment>
      {HERO_PHOTOS.map((p, idx) => (
        <img key={p.id} src={RES(p.id, p.src)} alt="" aria-hidden="true"
          style={{ position:'absolute', inset:0, width:'100%', height:'100%', objectFit:'cover',
            objectPosition:p.pos, opacity: idx === i ? 1 : 0, transition:'opacity 1.6s cubic-bezier(0.22,1,0.36,1)' }} />
      ))}
    </React.Fragment>
  );
}

/* full-bleed background media for a dark hero */
function HeroBg({ media, scrim = 'rgba(16,13,56,0.62)', sketch = 'sketch-commercial' }) {
  if (media === 'minimal') {
    return (
      <div aria-hidden="true" style={{ position:'absolute', inset:0,
        backgroundImage:'linear-gradient(rgba(255,255,255,0.05) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,0.05) 1px, transparent 1px)',
        backgroundSize:'48px 48px' }} />
    );
  }
  if (media === 'sketch') {
    return (
      <div aria-hidden="true" style={{ position:'absolute', inset:0, overflow:'hidden' }}>
        <img src={RES(sketch, `assets/${sketch}.png`)} alt="" aria-hidden="true"
          style={{ position:'absolute', right:'-4%', bottom:'-2%', width:'min(62vw,860px)', opacity:0.5,
            filter:'invert(1)', pointerEvents:'none' }} />
      </div>
    );
  }
  // real hero photographs, full bleed, crossfading
  return (
    <div aria-hidden="true" style={{ position:'absolute', inset:0 }}>
      <HeroPhotos />
      <div style={{ position:'absolute', inset:0, background:`linear-gradient(180deg, rgba(16,13,56,0.42) 0%, ${scrim} 58%, rgba(16,13,56,0.82) 100%)` }} />
    </div>
  );
}

function Hero({ onNav, dir = 'quiet', media = 'photo' }) {
  const eyebrow = 'Design · Build · Consult';
  const sub = 'A single design–build team carrying every project from first sketch to final walkthrough. Custom residential and commercial work across Southern California for nearly three decades.';

  /* ---------- QUIET: full-bleed, minimal text bottom-left ---------- */
  return (
    <section style={{ position:'relative', minHeight:'clamp(560px, 80vh, 840px)', background:'var(--akm-indigo-900)', overflow:'hidden',
      display:'flex', flexDirection:'column', justifyContent:'flex-end', padding:'116px 0 60px' }}>
      <HeroBg media={media} scrim="rgba(16,13,56,0.55)" />
      {media === 'minimal' && <Watermark opacity={0.05} />}
      <div style={{ position:'relative', maxWidth:1320, margin:'0 auto', padding:'0 clamp(20px,5vw,48px)', width:'100%' }}>
        <div className="reveal in" style={{ maxWidth:720 }}>
          <Eyebrow color="#fff">{eyebrow}</Eyebrow>
          <h1 style={{ fontFamily:'var(--font-display)', fontWeight:400, textTransform:'uppercase', color:'#fff',
            fontSize:'clamp(38px,5.6vw,76px)', lineHeight:1.05, letterSpacing:'0.03em', margin:'24px 0 0' }}>
            We build what you imagine
          </h1>
          <p style={{ fontFamily:'var(--font-body)', color:'rgba(255,255,255,.78)', fontSize:'clamp(16px,1.25vw,19px)',
            lineHeight:1.62, maxWidth:500, marginTop:26 }}>{sub}</p>
          <div style={{ marginTop:34 }}>
            <ArrowLink color="#fff" onClick={()=>onNav('work')}>View the work</ArrowLink>
          </div>
        </div>
      </div>

      {/* scroll cue */}
      <div style={{ position:'absolute', bottom:30, right:'clamp(20px,5vw,48px)',
        fontFamily:'var(--font-display)', fontSize:10.5, letterSpacing:'0.26em', textTransform:'uppercase',
        color:'rgba(255,255,255,.5)', display:'flex', flexDirection:'column', alignItems:'center', gap:10 }}>
        Scroll
        <span style={{ width:1, height:36, background:'rgba(255,255,255,.35)' }}></span>
      </div>
    </section>
  );
}

window.Hero = Hero;
