// v2-home.jsx — Home page

function HomePage2({ heroVideo, workLayout, onNavigate, onOpenProject, onContact }) {
  return (
    <div className="page2">
      <Hero2 videoUrl={heroVideo} onContact={onContact} onNavigate={onNavigate} />
      <StatBand2 />
      <Manifesto2 onNavigate={onNavigate} />
      <SelectedWork2 layout={workLayout} onNavigate={onNavigate} onOpenProject={onOpenProject} />
      <Testimonials2 />
      <Sectors2 onNavigate={onNavigate} />
      <Process2 onNavigate={onNavigate} />
      <Closing2 onContact={onContact} />
    </div>);

}

// ── STAT BAND — credibility (computed from the real catalog) ──
function StatBand2() {
  const sectors = new Set(PROJECTS.map(p => p.cat)).size;
  const stats = [
    { v: "50", s: "+", l: "Projects visualized" },
    { v: "10", s: "+", l: "Countries delivered to" },
    { v: sectors, s: "", l: "Sectors covered" },
    { v: "100", s: "%", l: "In-house, Lviv" },
  ];
  return (
    <section className="sec dark tight slim-b" data-screen-label="Home — proof">
      <Reveal><IndexLine n="—" tone="dark">By the numbers</IndexLine></Reveal>
      <div className="stat-band">
        {stats.map((st, i) => (
          <Reveal key={st.l} delay={i * 80}>
            <div className="stat-cell">
              <span className="stat-num">{st.v}<em>{st.s}</em></span>
              <span className="stat-lbl label">{st.l}</span>
            </div>
          </Reveal>
        ))}
      </div>
      <Reveal delay={360}>
        <div className="client-strip">
          <span className="label" style={{ color: "var(--w-3)" }}>Trusted by</span>
          <div className="client-names">
            {["KonzeptB", "Miviso", "3DRenderIT", "Concrete Bureau"].map(c => (
              <span key={c} className="client-name">{c}</span>
            ))}
            <span className="client-note">& several private clients</span>
          </div>
        </div>
      </Reveal>
    </section>);

}

// ── HERO ───────────────────────────────────────────────────────
function Hero2({ videoUrl, onContact, onNavigate }) {
  const videoRef = React.useRef(null);
  React.useEffect(() => {
    const v = videoRef.current;
    if (!v) return;
    v.muted = true;v.volume = 0;v.defaultMuted = true;
  }, [videoUrl]);

  return (
    <section className="hero2" data-screen-label="Home — hero">
      <div className="hero2-media">
        {videoUrl ?
        <video ref={videoRef} key={videoUrl} src={videoUrl} autoPlay muted loop playsInline></video> :

        <div className="hero2-fallback" style={{ background: PLATE_VARIANTS.dusk }}></div>
        }
        <div className="hero2-scrim"></div>
      </div>

      <div className="hero2-body">
        <h1 className="hero2-title">
          <Reveal as="span" auto delay={0} className="hero2-line">Architecture,</Reveal>
          <Reveal as="span" auto delay={150} className="hero2-line"><em>before</em> it exists.</Reveal>
        </h1>
        <Reveal auto delay={400} className="hero2-sub">
          <p>
            Photoreal stills, film and real-time experiences for architects
            and developers who need a building to be believed in — and bought —
            long before it is built.
          </p>
          <div className="cta-row">
            <GoldLink onClick={onContact}>Start a project</GoldLink>
            <a className="line-link dark" href="#/services" onClick={(e) => { e.preventDefault(); onNavigate && onNavigate("services"); }}>
              <span className="label">View pricing</span>
              <svg width="34" height="10" viewBox="0 0 34 10" fill="none" aria-hidden="true"><path d="M0 5h32M28 1l4 4-4 4" stroke="currentColor" strokeWidth="1" /></svg>
            </a>
          </div>
        </Reveal>
      </div>

      <div className="hero2-cue" aria-hidden="true">
        <span className="hero2-cue-line"></span>
        <span className="label" style={{ color: "var(--w-3)" }}>Scroll</span>
      </div>
    </section>);

}

// ── MANIFESTO ──────────────────────────────────────────────────
function Manifesto2({ onNavigate }) {
  return (
    <section className="sec light" data-screen-label="Home — manifesto">
      <Reveal><IndexLine n="01" tone="light">The studio</IndexLine></Reveal>
      <div className="manif-grid">
        <Reveal delay={100}>
          <h2 className="d2" style={{ color: "var(--b-1)" }}>
            A render shows a building.<br />
            <em>An image sells the idea of living in it.</em>
          </h2>
        </Reveal>
        <Reveal delay={220}>
          <div className="manif-copy">
            <p className="lead" style={{ color: "var(--b-2)" }}>
              Obsidian Studio works at the point where architecture meets
              its audience. We build light, weather, material and mood around
              your design — so a jury, an investor or a buyer doesn't evaluate
              a project. They want it.
            </p>
            <p style={{ color: "var(--b-3)" }}>
              Stills, animation and interactive Unreal Engine walkthroughs,
              produced end-to-end in-house in Lviv for clients across Europe.
            </p>
            <LineLink tone="light" onClick={() => onNavigate("about")}>About the studio</LineLink>
          </div>
        </Reveal>
      </div>
    </section>);

}

// ── SELECTED WORK — three layouts (cinematic · uniform · editorial) ──
function SelectedWork2({ layout = "cinematic", onNavigate, onOpenProject }) {
  const slugs = ["terrace-steps", "azure-wave", "wave-promenade", "timber-marble"];
  const works = slugs.map((s, i) => {
    const p = getProject(s);
    return {
      slug: s, id: String(i + 1).padStart(2, "0"), name: p.name,
      type: p.services[0].toLowerCase().startsWith(p.cat.toLowerCase()) ? p.cat : `${p.cat} · ${p.services[0]}`, place: p.year,
      place2: `${p.loc} · ${p.year}`,
      cover: p.cover, video: p.video
    };
  });

  return (
    <section className="sec dark tight slim-b" data-screen-label="Home — selected work">
      <Reveal>
        <div className="sec-head" style={{ marginBottom: "clamp(28px, 3vw, 48px)" }}>
          <IndexLine n="02" tone="dark">Selected work</IndexLine>
          <p className="ed-standfirst">Architecture made believable in light, weather and material — a decade before the crane arrives.</p>
        </div>
      </Reveal>

      {layout === "cinematic" &&
      <div className="sw-cine">
          {works.map((w) =>
        <Reveal key={w.slug}>
              <button type="button" className="sw-cine-item work-card" onClick={() => onOpenProject(w.slug)}>
                <Photo id={w.cover} ratio="21/9" w={2200} video={w.video} alt={w.name} />
                <div className="sw-cine-scrim"></div>
                <div className="sw-cine-cap">
                  <div className="sw-cine-top">
                    <span className="work-num label">{w.id}</span>
                    <span className="label" style={{ color: "var(--w-2)" }}>{w.type}</span>
                    <span className="sw-cine-view label">View project →</span>
                  </div>
                  <span className="sw-cine-title">{w.name}</span>
                  <span className="sw-cine-sub">{w.place2}</span>
                </div>
              </button>
            </Reveal>
        )}
        </div>
      }

      {layout === "uniform" &&
      <div className="sw-grid">
          {works.map((w) =>
        <Reveal key={w.slug}>
              <button type="button" className="work-card" onClick={() => onOpenProject(w.slug)}>
                <Photo id={w.cover} ratio="4/5" w={1400} video={w.video} alt={w.name} />
                <div className="work-cap">
                  <span className="work-num label">{w.id}</span>
                  <div className="work-names">
                    <span className="work-title">{w.name}</span>
                    <span className="label" style={{ color: "var(--w-3)" }}>{w.type}</span>
                  </div>
                </div>
              </button>
            </Reveal>
        )}
        </div>
      }

      {layout === "editorial" &&
      <div className="sw-edit">
          {works.map((w, i) =>
        <Reveal key={w.slug}>
              <button type="button" className={`sw-edit-item work-card ${i % 2 ? "flip" : ""}`} onClick={() => onOpenProject(w.slug)}>
                <div className="sw-edit-media"><Photo id={w.cover} ratio="4/3" w={1600} video={w.video} alt={w.name} /></div>
                <div className="sw-edit-text">
                  <span className="work-num label" style={{ color: "var(--accent)" }}>{w.id}</span>
                  <span className="sw-edit-title">{w.name}</span>
                  <span className="label" style={{ color: "var(--w-3)" }}>{w.type}</span>
                  <span className="sw-cine-view label" style={{ marginTop: 8 }}>View project →</span>
                </div>
              </button>
            </Reveal>
        )}
        </div>
      }

      <Reveal>
        <div className="work-more">
          <LineLink tone="dark" onClick={() => onNavigate("projects")}>View all work</LineLink>
        </div>
      </Reveal>
    </section>);

}

// ── SECTORS — hairline index table ─────────────────────────────
function Sectors2({ onNavigate }) {
  const rows = [
  { n: "01", t: "Residential", d: "Private houses to large-scale complexes" },
  { n: "02", t: "Commercial", d: "Offices, retail and mixed-use" },
  { n: "03", t: "Hospitality", d: "Hotels, restaurants, spas and resorts" },
  { n: "04", t: "Public", d: "Cultural, civic and infrastructure" },
  { n: "05", t: "Interactive", d: "Real-time Unreal Engine experiences" }];

  return (
    <section className="sec dark tight" data-screen-label="Home — sectors">
      <Reveal><IndexLine n="03" tone="dark">What we visualize</IndexLine></Reveal>
      <div className="sector-table" role="list">
        {rows.map((r, i) =>
        <Reveal key={r.n} delay={i * 60} as="div">
            <button type="button" className="sector-row" role="listitem" onClick={() => onNavigate("services")}>
              <span className="label sector-num">{r.n}</span>
              <span className="sector-title">{r.t}</span>
              <span className="sector-desc">{r.d}</span>
              <svg className="sector-arrow" width="34" height="10" viewBox="0 0 34 10" fill="none" aria-hidden="true">
                <path d="M0 5h32M28 1l4 4-4 4" stroke="currentColor" strokeWidth="1" />
              </svg>
            </button>
          </Reveal>
        )}
      </div>
    </section>);

}

// ── PROCESS ────────────────────────────────────────────────────
function Process2({ onNavigate }) {
  const steps = [
  { n: "01", t: "Vision", d: "A deep read of the project — drawings, models, marketing goals — until both sides see the same final image." },
  { n: "02", t: "Atmosphere", d: "Light, weather, materials and camera language. The small, deliberate details that make a frame feel inhabited." },
  { n: "03", t: "Creation", d: "Photoreal stills and film, refined through several internal quality passes before anything reaches you." },
  { n: "04", t: "Delivery", d: "Final materials, formatted for the boardroom, the sales floor and the printing house." }];

  return (
    <section className="sec light" data-screen-label="Home — process">
      <Reveal>
        <div className="sec-head">
          <IndexLine n="04" tone="light">Method</IndexLine>
          <h2 className="d2" style={{ color: "var(--b-1)" }}>Four movements,<br /><em>one standard.</em></h2>
        </div>
      </Reveal>
      <div className="proc-grid">
        {steps.map((s, i) =>
        <Reveal key={s.n} delay={i * 90}>
            <div className="proc-cell">
              <span className="label" style={{ color: "var(--accent-deep)" }}>{s.n}</span>
              <h3 className="d4">{s.t}</h3>
              <p>{s.d}</p>
            </div>
          </Reveal>
        )}
      </div>
      <Reveal>
        <div className="work-more light">
          <LineLink tone="light" onClick={() => onNavigate("about")}>The full method</LineLink>
        </div>
      </Reveal>
    </section>);

}

// ── TESTIMONIALS ───────────────────────────────────────────────
function Testimonials2() {
  const quotes = [
    { q: "Obsidian turned our concept drawings into images our clients fell for before ground was even broken. The light, the mood — that's the difference between showing a building and selling one.", n: "Laurenz", c: "KonzeptB" },
    { q: "As a studio ourselves, we're hard to impress. Obsidian's frames hold up at any crop — the craft in the materials and lighting is genuinely rare.", n: "Marko", c: "3DRenderIT" },
    { q: "Fast, precise and quietly obsessive about detail. Every round came back better than we asked for — and always on time.", n: "Philip", c: "Miviso" },
    { q: "They read the architecture the way we do. The visuals didn't just document our design — they gave it atmosphere and made the jury believe in it.", n: "Alex", c: "Concrete Bureau" },
  ];
  return (
    <section className="sec light" data-screen-label="Home — testimonials">
      <Reveal>
        <div className="sec-head" style={{ marginBottom: "clamp(16px, 2vw, 28px)" }}>
          <IndexLine n="—" tone="light">Client voices</IndexLine>
          <h2 className="d2" style={{ color: "var(--b-1)" }}>Trusted where it<br /><em>matters most.</em></h2>
        </div>
      </Reveal>
      <div className="quote-grid">
        {quotes.map((t, i) => (
          <Reveal key={t.n} delay={i * 90}>
            <figure className="quote-item">
              <span className="quote-mark" aria-hidden="true">“</span>
              <blockquote className="quote-text">{t.q}</blockquote>
              <figcaption className="quote-attr">
                <span className="quote-name">{t.n}</span>
                <span className="quote-co label">{t.c}</span>
              </figcaption>
            </figure>
          </Reveal>
        ))}
      </div>
    </section>);

}

// ── CLOSING ────────────────────────────────────────────────────
function Closing2({ onContact }) {
  return (
    <section className="closing" data-screen-label="Home — closing">
      <Reveal>
        <span className="label" style={{ color: "var(--w-3)" }}>New projects — 2026</span>
      </Reveal>
      <Reveal delay={120}>
        <h2 className="d1" style={{ color: "var(--w-1)" }}>
          Let's make your next<br /><em>unbuilt building</em> unforgettable.
        </h2>
      </Reveal>
      <Reveal delay={240}>
        <div className="cta-row">
          <GoldLink onClick={onContact}>Start a project</GoldLink>
          <a className="line-link dark" href="#/services" onClick={(e) => { e.preventDefault(); location.hash = "#/services"; }}>
            <span className="label">See pricing &amp; packages</span>
            <svg width="34" height="10" viewBox="0 0 34 10" fill="none" aria-hidden="true"><path d="M0 5h32M28 1l4 4-4 4" stroke="currentColor" strokeWidth="1" /></svg>
          </a>
        </div>
      </Reveal>
    </section>);

}

Object.assign(window, { HomePage2, StatBand2, Testimonials2 });