/* Home — PAS, problem-first. README-driven. Globals from shared.jsx. */
const HomeDS = window.ZeroZ4JDesignSystem_f7e0ed;

/* HERO — leads with the PROBLEM. No code, single balanced column + meta bar. */
function Hero() {
  return (
    <div style={{ minHeight: "88vh", display: "flex", flexDirection: "column", borderBottom: "1px solid var(--color-steel)", position: "relative" }}>
      <div style={{ flex: 1, display: "flex", alignItems: "center", padding: "96px 64px" }}>
        <div style={{ maxWidth: 1440, margin: "0 auto", width: "100%" }}>
          <Eyebrow tone="brass">The Problem · Architectural impedance</Eyebrow>
          <h1 style={{ fontFamily: "var(--font-sans)", fontWeight: 300, fontSize: "clamp(44px, 6.4vw, 96px)", letterSpacing: "var(--tracking-tight)", lineHeight: 1.0, color: "var(--color-bone)", margin: 0, maxWidth: 1180, textWrap: "balance" }}>
            Java Enterprise web development is drowning in <Serif>translation layers.</Serif>
          </h1>
          <p style={{ fontFamily: "var(--font-sans)", fontSize: "var(--text-20)", color: "var(--color-ash)", maxWidth: 660, marginTop: 32, lineHeight: 1.5, textWrap: "pretty" }}>
            Four languages, four paradigms, three copies of every model. A stack so fragmented that neither your engineers nor your AI coding agents can hold it in a single coherent view — and every layer is a place where cost, safety, and comprehension collapse.
          </p>
          <div style={{ display: "flex", gap: 12, marginTop: 40 }}>
            <a href="#agitate" style={{ textDecoration: "none" }}><HomeDS.Button variant="primary">See the Cost</HomeDS.Button></a>
            <a href="about.html" style={{ textDecoration: "none" }}><HomeDS.Button variant="secondary">Why this was built</HomeDS.Button></a>
          </div>
        </div>
      </div>
      <div style={{ borderTop: "1px solid var(--color-steel)" }}>
        <div style={{ maxWidth: 1440, margin: "0 auto", display: "grid", gridTemplateColumns: "repeat(4, 1fr)", fontFamily: "var(--font-mono)", fontSize: "var(--text-12)" }}>
          {[
          ["Nature", "Pure-Java reference architecture"],
          ["Thesis", "Radical simplification is possible"],
          ["Author", "Franz Schöning · Enterprise AI Architect"],
          ["Source", <a key="s" href={GITHUB} target="_blank" rel="noopener" style={{ color: "var(--color-brass)", textDecoration: "none" }}>github.com/fschoning/zeroz4j ↗</a>]].
          map(([k, v], i) =>
          <div key={k} style={{ padding: "24px 28px", borderLeft: i ? "1px solid var(--color-steel)" : "none" }}>
              <div style={{ color: "var(--color-ash)", textTransform: "uppercase", letterSpacing: "var(--tracking-wide)", fontSize: "var(--text-10)", marginBottom: 10 }}>{k}</div>
              <div style={{ color: "var(--color-bone)", lineHeight: 1.4 }}>{v}</div>
            </div>
          )}
        </div>
      </div>
    </div>);

}

/* AGITATE — the four mismatches from README §1. AI context collapse highlighted. */
function Agitate() {
  const pains = [
  { t: "The database mismatch", b: "Domain models in Java are translated via SQL or JPA/Hibernate to map onto relational tables — creating dual-schema maintenance for a single idea." },
  { t: "The network mismatch", b: "Java objects are serialized into text (JSON), sent over HTTP, and parsed back into JavaScript/TypeScript objects on the client. Every field crosses on faith." },
  { t: "The UI mismatch", b: "JavaScript or TypeScript is required to mutate a browser DOM — fracturing the codebase's language ecosystem in the one place Java never reached." },
  { t: "AI context collapse", b: "An AI coding agent must hold context across four languages and paradigms — SQL, Java, JSON, TS/JS. That load causes hallucinations, broken contracts, and security holes.", cyan: true }];

  return (
    <Section id="agitate">
      <div style={{ maxWidth: 700, margin: "0 auto 80px", textAlign: "center" }}>
        <Eyebrow>The Cost</Eyebrow>
        <H2 style={{ margin: "0 auto" }}>Every boundary is a place to <Serif>bleed.</Serif></H2>
        <p style={{ fontFamily: "var(--font-sans)", fontSize: "var(--text-16)", color: "var(--color-ash)", margin: "24px auto 0", lineHeight: 1.6, maxWidth: 600 }}>
          Modern enterprise web development is drowning in translation layers — massive friction for human developers, and catastrophic context collapse for AI coding agents.
        </p>
      </div>
      <div style={{ display: "grid", gridTemplateColumns: "repeat(2, 1fr)", border: "1px solid var(--color-steel)", borderLeft: "none", borderTop: "none" }}>
        {pains.map((p) =>
        <div key={p.t} style={{ borderLeft: "1px solid var(--color-steel)", borderTop: "1px solid var(--color-steel)", background: "var(--color-graphite)", padding: "64px 56px", display: "flex", flexDirection: "column", alignItems: "center", textAlign: "center" }}>
            <h3 style={{ fontFamily: "var(--font-sans)", fontWeight: 400, fontSize: "var(--text-20)", color: p.cyan ? "var(--color-cyan)" : "var(--color-bone)", letterSpacing: "-0.01em", margin: 0, lineHeight: 1.2 }}>{p.t}</h3>
            <p style={{ fontFamily: "var(--font-sans)", fontSize: "var(--text-16)", color: "var(--color-ash)", margin: "20px 0 0", lineHeight: 1.65, maxWidth: 400 }}>{p.b}</p>
          </div>
        )}
      </div>
      <p style={{ fontFamily: "var(--font-sans)", fontWeight: 300, fontSize: "var(--text-28)", color: "var(--color-bone)", letterSpacing: "var(--tracking-tight)", lineHeight: 1.35, margin: "80px auto 0", maxWidth: 860, textAlign: "center", textWrap: "balance" }}>
        Every translation layer breaks static analysis, prevents fearless refactoring, and forces the application to maintain <Serif>three different models</Serif> of the exact same data.
      </p>
    </Section>);

}

/* SOLUTION — one object model across every domain + real backend logic. README §2. */
function Solution() {
  const rows = [
  { d: "Browser UI", conv: "TypeScript / React", z4: "Java → WebAssembly" },
  { d: "Transport", conv: "JSON over REST/HTTP", z4: "Binary RPC over WebSocket" },
  { d: "Server logic", conv: "Java + mapping layers", z4: "Java (Jakarta EE / CDI)" },
  { d: "Persistence", conv: "SQL / JPA / Hibernate", z4: "Java object graph (EclipseStore)" }];

  return (
    <Section style={{ background: "var(--color-vault)" }}>
      <div style={{ maxWidth: 900, marginBottom: 64 }}>
        <Eyebrow tone="brass">The Solution</Eyebrow>
        <H2 style={{ fontSize: "clamp(40px, 4.8vw, 68px)", lineHeight: 1.04 }}>Impedance, <Serif>eliminated.</Serif></H2>
        <p style={{ fontFamily: "var(--font-sans)", fontSize: "var(--text-20)", color: "var(--color-ash)", marginTop: 28, lineHeight: 1.5, maxWidth: 700, textWrap: "pretty" }}>
          No ORM. No JSON. No JavaScript. The translation layers aren't optimized — they're <span style={{ color: "var(--color-bone)" }}>gone.</span> One Java object runs from the button click to the stored byte, never re-encoded, never duplicated, never translated.
        </p>
      </div>
      {/* Domain map: the same object model across every layer */}
      <div style={{ border: "1px solid var(--color-steel)" }}>
        <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr 1fr", background: "var(--color-graphite)", borderBottom: "1px solid var(--color-steel)" }}>
          {["Domain", "Conventional stack", "ZeroZ4j"].map((h, i) =>
          <div key={h} style={{ padding: "16px 28px", borderLeft: i ? "1px solid var(--color-steel)" : "none", fontFamily: "var(--font-mono)", fontSize: "var(--text-10)", textTransform: "uppercase", letterSpacing: "var(--tracking-wide)", color: i === 2 ? "var(--color-brass)" : "var(--color-ash)" }}>{h}</div>
          )}
        </div>
        {rows.map((r, i) =>
        <div key={r.d} style={{ display: "grid", gridTemplateColumns: "1fr 1fr 1fr", borderTop: i ? "1px solid var(--color-steel)" : "none" }}>
            <div style={{ padding: "22px 28px", fontFamily: "var(--font-sans)", fontSize: "var(--text-16)", color: "var(--color-bone)" }}>{r.d}</div>
            <div style={{ padding: "22px 28px", borderLeft: "1px solid var(--color-steel)", fontFamily: "var(--font-mono)", fontSize: "var(--text-14)", color: "var(--color-ash)" }}>{r.conv}</div>
            <div style={{ padding: "22px 28px", borderLeft: "1px solid var(--color-steel)", fontFamily: "var(--font-mono)", fontSize: "var(--text-14)", color: "var(--color-brass)", background: "var(--color-graphite)" }}>{r.z4}</div>
          </div>
        )}
        <div style={{ borderTop: "1px solid var(--color-steel)", padding: "18px 28px", fontFamily: "var(--font-mono)", fontSize: "var(--text-12)", color: "var(--color-ash)", background: "var(--color-vault)" }}>
          <span style={{ color: "var(--color-cyan)" }}>◆</span> Every ZeroZ4j column is the same language — and the same <span style={{ color: "var(--color-bone)" }}>ChatMessage</span> object, unchanged from browser to disk.
        </div>
      </div>

      {/* Backend business logic — the object arrives exactly as sent */}
      <div style={{ display: "grid", gridTemplateColumns: "380px 1fr", gap: 64, marginTop: 64, alignItems: "center" }}>
        <div>
          <h3 style={{ fontFamily: "var(--font-sans)", fontWeight: 300, fontSize: "var(--text-28)", color: "var(--color-bone)", letterSpacing: "var(--tracking-tight)", margin: 0, lineHeight: 1.15 }}>
            Business logic, <Serif>no plumbing.</Serif>
          </h3>
          <p style={{ fontFamily: "var(--font-sans)", fontSize: "var(--text-16)", color: "var(--color-ash)", marginTop: 20, lineHeight: 1.6 }}>
            The server method receives the exact object the client sent — no controller, no deserialization, no mapping. Persist it or broadcast it as plain Java.
          </p>
        </div>
        <CodeBlock file="ChatServiceImpl.java" lang="SERVER" badge="● CDI bean" badgeTone="tech">
{cy("@ApplicationScoped")}{"\n"}
{kw("public class")} ChatServiceImpl {kw("implements")} ChatService {"{"}{"\n"}
{"    "}{cy("@Inject")} EmbeddedStorageManager storage;{"\n\n"}
{"    "}{cy("@Override")}{"\n"}
{"    "}{kw("public")} {kw("void")} sendMessage(ChatMessage msg) {"{"}{"\n"}
{"        "}{cm("// the exact object sent from the client")}{"\n"}
{"        "}DataRoot root = (DataRoot) storage.root();{"\n"}
{"        "}root.getMessages().add(msg);{"\n"}
{"        "}storage.store(root.getMessages());{"\n"}
{"    "}{"}"}{"\n"}
{"}"}
        </CodeBlock>
      </div>

      <div style={{ marginTop: 56, border: "1px solid var(--color-steel)", borderLeft: "3px solid var(--color-cyan)", background: "var(--color-graphite)", padding: "32px 40px" }}>
        <p style={{ fontFamily: "var(--font-sans)", fontSize: "var(--text-20)", color: "var(--color-bone)", margin: 0, lineHeight: 1.5, maxWidth: 860, textWrap: "pretty" }}>
          Because the stack is unified, <span style={{ color: "var(--color-cyan)" }}>AI coding agents can generate end-to-end features with near-perfect accuracy</span>, and human developers can refactor from the database to the button-click with a single IDE command.
        </p>
      </div>
    </Section>);

}

/* PILLARS — README §3 A/B/C */
function Pillars() {
  const cards = [
  { i: "PILLAR.A", t: "Native object persistence", b: "EclipseStore bypasses the object-relational mismatch entirely — no UPDATE statements, no N+1 queries. The in-memory graph is explicitly saved; realtime UI updates can be implicit via @LiveSync." },
  { i: "PILLAR.B", t: "Binary RPC + Project Loom", b: "REST and JSON are discarded for a custom binary protocol over persistent WebSockets. Virtual Threads absorb thousands of connections, so I/O threads never block during processing." },
  { i: "PILLAR.C", t: "AOT compilation, zero DOM state", b: "TeaVM AOT and compile-time annotation processors avoid runtime reflection. Unlike Vaadin, ZeroZ4j keeps zero server-side DOM state — components live entirely in the client Wasm heap." }];

  return (
    <Section>
      <div style={{ maxWidth: 820, marginBottom: 56 }}>
        <Eyebrow>Architectural pillars</Eyebrow>
        <H2>Curated for concurrency and <Serif>correctness.</Serif></H2>
      </div>
      <div style={{ display: "grid", gridTemplateColumns: "repeat(3, 1fr)", border: "1px solid var(--color-steel)", borderLeft: "none" }}>
        {cards.map((c) =>
        <div key={c.i} style={{ borderLeft: "1px solid var(--color-steel)" }}>
            <HomeDS.Card title={c.t}>{c.b}</HomeDS.Card>
          </div>
        )}
      </div>
      <div style={{ marginTop: 32, display: "flex", gap: 12 }}>
        <a href="docs.html" style={{ textDecoration: "none" }}><HomeDS.Button variant="secondary">Read the Docs</HomeDS.Button></a>
        <a href="protocol.html" style={{ textDecoration: "none" }}><HomeDS.Button variant="ghost">Protocol spec →</HomeDS.Button></a>
      </div>
    </Section>);

}

function Home() {
  return (
    <Page page="home">
      <Hero />
      <Agitate />
      <Solution />
      <Pillars />
    </Page>);

}

ReactDOM.createRoot(document.getElementById("root")).render(<Home />);