const { useState: _useState1, useEffect: _useEffect1, useRef: _useRef1 } = React;

// ─── HERO ─────────────────────────────────────────────────────────────────
function Hero() {
  const { t } = useLang();
  const h = t('hero');
  const [vis, setVis] = _useState1(false);
  _useEffect1(() => { setTimeout(() => setVis(true), 80); }, []);
  const fi = delay => ({ opacity: vis ? 1 : 0, transform: vis ? 'translateY(0)' : 'translateY(22px)', transition: `opacity 0.7s ease ${delay}ms, transform 0.7s ease ${delay}ms` });

  return (
    <section style={{ minHeight: '100vh', padding: '120px 48px 80px', display: 'flex', alignItems: 'center', overflow: 'hidden' }}>
      <div style={{ maxWidth: 1280, margin: '0 auto', width: '100%', display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 80, alignItems: 'center' }} className="hero-grid">
        <div>
          <h1 style={{ ...fi(60), fontFamily: 'Fraunces, serif', fontSize: 'clamp(40px,4.8vw,64px)', fontWeight: 700, lineHeight: 1.08, letterSpacing: '-0.02em', marginBottom: 22, color: '#2A0E1A' }}>
            {h.titleLine1} <span className="grad-text">{h.titleAccent}</span>
          </h1>
          <p style={{ ...fi(120), fontFamily: 'DM Sans, sans-serif', fontSize: 18, lineHeight: 1.65, color: 'rgba(42,14,26,0.7)', marginBottom: 32, maxWidth: 520 }}>
            {h.subtitlePre}<strong style={{ color: '#2A0E1A', fontWeight: 600 }}>{h.subtitleStrong}</strong>{h.subtitlePost}
          </p>
          <div style={{ ...fi(200), display: 'flex', gap: 14, flexWrap: 'wrap', marginBottom: 18 }}>
            <a href="#quote-form" className="btn-primary">
              {h.ctaPrimary}
              <svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5"><path d="M5 12h14M12 5l7 7-7 7"/></svg>
            </a>
            <a href="#services" className="btn-outline">
              {h.ctaSecondary}
              <svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5"><path d="M5 12h14M12 5l7 7-7 7"/></svg>
            </a>
          </div>
          <p style={{ ...fi(260), fontFamily: 'DM Sans, sans-serif', fontSize: 13, color: 'rgba(42,14,26,0.45)' }}>
            {h.microcopy}
          </p>
        </div>

        {/* Product Showcase Cluster */}
        <div className="hero-visual" style={{ position: 'relative', height: 540 }}>
          {/* Website mockup — back, large, slightly rotated */}
          <div style={{ position: 'absolute', top: '14%', left: '6%', width: '78%', transform: 'rotate(-3deg)', zIndex: 1, boxShadow: '0 12px 40px rgba(110,2,64,0.18)', borderRadius: 12 }}>
            <PlaceholderWebsite zone="hero-website-1" label="Sample post — replace with real content" image="assets/hero-website.png" />
          </div>
          {/* Square Instagram — front-left */}
          <div style={{ position: 'absolute', bottom: '4%', left: '0%', width: '38%', transform: 'rotate(-6deg)', zIndex: 3, boxShadow: '0 12px 40px rgba(214,4,87,0.18)', borderRadius: 12 }}>
            <Placeholder zone="hero-square-1" aspect="1:1" label="Sample post — replace with real content" image="assets/hero-square.png" />
          </div>
          {/* Portrait story — front-right */}
          <div style={{ position: 'absolute', top: '0%', right: '0%', width: '28%', transform: 'rotate(5deg)', zIndex: 4, boxShadow: '0 12px 40px rgba(255,199,28,0.22)', borderRadius: 12 }}>
            <Placeholder zone="hero-portrait-1" aspect="9:16" label="Sample post — replace with real content" image="assets/hero-portrait.png" />
          </div>
        </div>
      </div>
    </section>
  );
}

// ─── 2. WHAT WE BUILD ─────────────────────────────────────────────────────
function WhatWeBuild() {
  const { t } = useLang();
  const wb = t('whatWeBuild');
  const [ref, inView] = useInView(0.1);
  const meta = [
    { zone: 'whatwebuild-website', aspect: 'website', image: 'assets/cappas-website.png', link: 'https://cappaslandscaping.com' },
    { zone: 'whatwebuild-square', aspect: '1:1', image: 'assets/landscaping-services.png' },
    { zone: 'whatwebuild-portrait', aspect: '9:16', image: 'assets/landscaping-social-post.png' },
  ];
  const cards = wb.cards.map((c, i) => ({ ...c, ...meta[i] }));
  return (
    <section id="services" style={{ padding: '120px 48px' }}>
      <div ref={ref} style={{ maxWidth: 1280, margin: '0 auto' }}>
        <div style={{ textAlign: 'center', marginBottom: 36, opacity: inView?1:0, transform: inView?'translateY(0)':'translateY(22px)', transition: 'opacity 0.7s, transform 0.7s' }}>
          <div style={{ marginBottom: 12 }}><span style={{ fontFamily: 'DM Sans, sans-serif', fontSize: 11, fontWeight: 600, letterSpacing: '0.14em', textTransform: 'uppercase', color: 'rgba(42,14,26,0.35)' }}>{wb.eyebrow}</span></div>
          <h2 style={{ fontFamily: 'Fraunces, serif', fontSize: 'clamp(30px,3.2vw,46px)', fontWeight: 700, lineHeight: 1.1, letterSpacing: '-0.02em', color: '#2A0E1A', marginBottom: 14 }}>{wb.title}</h2>
          <p style={{ fontFamily: 'DM Sans, sans-serif', fontSize: 17, color: 'rgba(42,14,26,0.5)', maxWidth: 480, margin: '0 auto' }}>{wb.subtitle}</p>
        </div>
        <div style={{ display: 'flex', justifyContent: 'flex-start', marginBottom: 20, opacity: inView?1:0, transform: inView?'translateY(0)':'translateY(18px)', transition: 'opacity 0.7s ease 80ms, transform 0.7s ease 80ms' }}>
          <div style={{ display: 'inline-flex', alignItems: 'center', gap: 7, padding: '7px 16px', borderRadius: 100, background: 'rgba(40,180,99,0.14)', border: '1px solid rgba(40,180,99,0.4)' }}>
            <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="#1f8a4c" strokeWidth="3"><path d="M20 6L9 17l-5-5"/></svg>
            <span style={{ fontFamily: 'DM Sans, sans-serif', fontSize: 11.5, fontWeight: 700, color: '#1f8a4c', letterSpacing: '0.06em', textTransform: 'uppercase' }}>{wb.realClientWork}</span>
          </div>
        </div>
        <div style={{ display: 'grid', gridTemplateColumns: 'repeat(3,1fr)', gap: 18 }} className="services-grid">
          {cards.map((c, i) => (
            <div key={i} data-tilt="" className="glass" style={{
              borderRadius: 20, padding: 26,
              opacity: inView?1:0, transform: inView?'translateY(0)':'translateY(26px)',
              transition: `opacity 0.7s ease ${i*90}ms, transform 0.7s ease ${i*90}ms`,
              display: 'flex', flexDirection: 'column', gap: 18,
            }}>
              <div style={{ position: 'relative', background: 'rgba(255,248,240,0.6)', borderRadius: 12, padding: 14, border: '1px solid rgba(42,14,26,0.06)' }}>
                {c.link ? (
                  <a href={c.link} target="_blank" rel="noopener noreferrer" style={{ display: 'block' }}>
                    {c.aspect === 'website'
                      ? <PlaceholderWebsite zone={c.zone} label="Sample post — replace with real content" image={c.image} />
                      : <Placeholder zone={c.zone} aspect={c.aspect} label="Sample post — replace with real content" image={c.image} />}
                  </a>
                ) : (
                  c.aspect === 'website'
                    ? <PlaceholderWebsite zone={c.zone} label="Sample post — replace with real content" image={c.image} />
                    : <Placeholder zone={c.zone} aspect={c.aspect} label="Sample post — replace with real content" image={c.image} />
                )}
              </div>
              <div>
                <h3 style={{ fontFamily: 'Fraunces, serif', fontSize: 22, fontWeight: 700, color: '#2A0E1A', marginBottom: 10, letterSpacing: '-0.01em' }}>{c.title}</h3>
                <p style={{ fontFamily: 'DM Sans, sans-serif', fontSize: 15, lineHeight: 1.6, color: 'rgba(42,14,26,0.6)', marginBottom: 16 }}>{c.body}</p>
                <div style={{ display: 'flex', flexDirection: 'column', gap: 10 }}>
                  <a href="#sample-work" style={{ fontFamily: 'DM Sans, sans-serif', fontSize: 14, fontWeight: 600, color: '#D60457', textDecoration: 'none', display: 'inline-flex', alignItems: 'center', gap: 6 }}>
                    {wb.viewSamples}
                    <svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5"><path d="M5 12h14M12 5l7 7-7 7"/></svg>
                  </a>
                  {c.link && (
                    <a href={c.link} target="_blank" rel="noopener noreferrer" style={{ fontFamily: 'DM Sans, sans-serif', fontSize: 14, fontWeight: 600, color: '#1f8a4c', textDecoration: 'none', display: 'inline-flex', alignItems: 'center', gap: 6 }}>
                      {wb.viewWebsite}
                      <svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5"><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/><polyline points="15 3 21 3 21 9"/><line x1="10" y1="14" x2="21" y2="3"/></svg>
                    </a>
                  )}
                </div>
              </div>
            </div>
          ))}
        </div>
      </div>
    </section>
  );
}

// ─── VALUE BADGES ─────────────────────────────────────────────────────────
function ValueBadges() {
  const { t } = useLang();
  const vb = t('valueBadges');
  const [ref, inView] = useInView(0.1);

  return (
    <section style={{ padding: '0 48px 56px' }}>
      <div
        ref={ref}
        style={{
          maxWidth: 1280, margin: '0 auto',
          display: 'flex', flexWrap: 'wrap', justifyContent: 'center', gap: 12,
          opacity: inView?1:0, transform: inView?'translateY(0)':'translateY(16px)', transition: 'opacity 0.7s, transform 0.7s',
        }}
      >
        {vb.items.map((label, i) => (
          <div key={i} style={{ display: 'inline-flex', alignItems: 'center', gap: 8, padding: '9px 18px', borderRadius: 100, background: 'rgba(255,255,255,0.6)', border: '1px solid rgba(110,2,64,0.1)', backdropFilter: 'blur(8px)' }}>
            <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="#D60457" strokeWidth="3"><path d="M20 6L9 17l-5-5"/></svg>
            <span style={{ fontFamily: 'DM Sans, sans-serif', fontSize: 13.5, fontWeight: 600, color: '#2A0E1A' }}>{label}</span>
          </div>
        ))}
      </div>
    </section>
  );
}

// ─── TESTIMONIALS ─────────────────────────────────────────────────────────
function Testimonials() {
  const { t } = useLang();
  const ts = t('testimonials');
  const [ref, inView] = useInView(0.1);
  const loop = [...ts.items, ...ts.items];

  return (
    <section style={{ padding: '0 0 110px' }}>
      <div ref={ref} style={{ maxWidth: 1280, margin: '0 auto', padding: '0 48px', textAlign: 'center', marginBottom: 44, opacity: inView?1:0, transform: inView?'translateY(0)':'translateY(22px)', transition: 'opacity 0.7s, transform 0.7s' }}>
        <div style={{ marginBottom: 12 }}><span style={{ fontFamily: 'DM Sans, sans-serif', fontSize: 11, fontWeight: 600, letterSpacing: '0.14em', textTransform: 'uppercase', color: 'rgba(42,14,26,0.35)' }}>{ts.eyebrow}</span></div>
        <h2 style={{ fontFamily: 'Fraunces, serif', fontSize: 'clamp(28px,3vw,42px)', fontWeight: 700, lineHeight: 1.1, letterSpacing: '-0.02em', color: '#2A0E1A', marginBottom: 14 }}>{ts.title}</h2>
        <p style={{ fontFamily: 'DM Sans, sans-serif', fontSize: 16, color: 'rgba(42,14,26,0.5)', maxWidth: 480, margin: '0 auto' }}>{ts.subtitle}</p>
      </div>

      <div className="marquee-wrap">
        <div className="marquee-track" style={{ gap: 22, padding: '6px 0', animationDuration: '52s' }}>
          {loop.map((item, i) => (
            <div key={i} className="glass" style={{ width: 340, flexShrink: 0, borderRadius: 18, padding: 24, display: 'flex', flexDirection: 'column', gap: 14 }}>
              <div style={{ display: 'flex', gap: 3 }}>
                {Array.from({ length: 5 }).map((_, j) => (
                  <svg key={j} width="15" height="15" viewBox="0 0 24 24" fill="#FFC71C"><path d="M12 2l2.9 6.6 7.1.6-5.4 4.7 1.6 7-6.2-3.7-6.2 3.7 1.6-7L2 9.2l7.1-.6z"/></svg>
                ))}
              </div>
              <p style={{ fontFamily: 'DM Sans, sans-serif', fontSize: 14.5, lineHeight: 1.6, color: 'rgba(42,14,26,0.7)', flex: 1 }}>
                "{item.quote}"
              </p>
              <div style={{ display: 'flex', alignItems: 'center', gap: 12 }}>
                <div style={{ width: 42, height: 42, borderRadius: '50%', flexShrink: 0, background: 'linear-gradient(135deg, #F62E33, #6E0240)', display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
                  <span style={{ fontFamily: 'Fraunces, serif', fontWeight: 700, fontSize: 15, color: '#FFF8F0' }}>{item.name.split(' ').map(w => w[0]).join('').slice(0, 2)}</span>
                </div>
                <div>
                  <div style={{ fontFamily: 'DM Sans, sans-serif', fontSize: 14, fontWeight: 700, color: '#2A0E1A' }}>{item.name}</div>
                  <div style={{ fontFamily: 'DM Sans, sans-serif', fontSize: 12, color: 'rgba(42,14,26,0.45)' }}>{item.role}</div>
                </div>
              </div>
            </div>
          ))}
        </div>
      </div>
    </section>
  );
}

window.Hero = Hero;
window.WhatWeBuild = WhatWeBuild;
window.ValueBadges = ValueBadges;
window.Testimonials = Testimonials;
