/* Four products, stacked full-width rows */

const ProductRow = ({ idx, name, slug, oneLine, problem, body, points, visual, href }) => (
  <article style={{ borderTop: "1px solid var(--rule)", padding: "80px 0" }}>
    <div className="shell">
      <div style={{ display: "grid", gridTemplateColumns: "1fr 1.15fr", gap: 80, alignItems: "start" }}>
        <div>
          <div style={{ display: "flex", justifyContent: "space-between", alignItems: "baseline", marginBottom: 32 }}>
            <Marker section={`02.${String(idx).padStart(2, "0")}`} label="PRODUCT" />
            <span className="mono" style={{ fontSize: 11, color: "var(--fg-faint)", letterSpacing: "0.08em" }}>0{idx} / 04</span>
          </div>
          <h3 className="h-product reveal" style={{ marginBottom: 18 }}>
            {name}
          </h3>
          <p className="reveal" style={{ fontSize: 19, color: "var(--fg-dim)", lineHeight: 1.5, letterSpacing: "-0.008em", marginBottom: 32, maxWidth: 480 }}>
            {oneLine}
          </p>
          <div style={{ borderLeft: "1px solid var(--rule-strong)", paddingLeft: 18, marginBottom: 28 }}>
            <div className="eyebrow" style={{ marginBottom: 8 }}>The problem</div>
            <p style={{ color: "var(--fg-dim)", margin: 0, fontSize: 14.5, lineHeight: 1.6 }}>{problem}</p>
          </div>
          <p style={{ color: "var(--fg-dim)", marginBottom: 28, fontSize: 14.5, lineHeight: 1.7, maxWidth: 480 }}>{body}</p>
          <ul style={{ listStyle: "none", padding: 0, margin: "0 0 36px", borderTop: "1px solid var(--rule)" }}>
            {points.map((pt) => (
              <li key={pt.k} style={{ borderBottom: "1px solid var(--rule)", display: "grid", gridTemplateColumns: "180px 1fr", gap: 24, padding: "12px 0", alignItems: "baseline" }}>
                <span className="mono" style={{ color: "var(--fg-faint)", fontSize: 11, letterSpacing: "0.08em", textTransform: "uppercase" }}>{pt.k}</span>
                <span style={{ color: "var(--fg)", fontSize: 14.5 }}>{pt.v}</span>
              </li>
            ))}
          </ul>
          <div style={{ display: "flex", gap: 12, flexWrap: "wrap" }}>
            <a href={href} className="btn btn--primary">Open {name} <span className="arrow">→</span></a>
            <a href="#waitlist" className="btn">Get access</a>
          </div>
        </div>
        <div style={{ position: "sticky", top: 100 }}>{visual}</div>
      </div>
    </div>
  </article>
);

/* Visual: Marketplace — listing rows */
const VisualMarketplace = () => (
  <div className="diag scan" style={{ padding: 24, position: "relative" }}>
    <Crosshairs />
    <div className="coord-label" style={{ top: 12, left: 14 }}>FIG.M01</div>
    <div className="coord-label" style={{ top: 12, right: 14 }}>EXTODAN / MARKETPLACE</div>
    <div style={{ marginTop: 32 }}>
      <div className="mono" style={{ fontSize: 11, color: "var(--fg-faint)", letterSpacing: "0.08em", textTransform: "uppercase", display: "grid", gridTemplateColumns: "2.4fr 1fr 1fr 1fr", gap: 16, padding: "10px 4px", borderBottom: "1px solid var(--rule)" }}>
        <span>Endpoint</span><span>Price</span><span>Latency</span><span>Calls/24h</span>
      </div>
      {[
        ["weather-pro/forecast", "$0.0010", "412ms", "1.24M", "ok"],
        ["llm-router/chat", "$0.0040", "892ms", "8.91M", "ok"],
        ["satellite/imagery-v2", "$0.012", "1.4s", "112K", "ok"],
        ["geocode/reverse", "$0.0002", "88ms", "44.2M", "ok"],
        ["sentiment/news-firehose", "$0.0009", "256ms", "920K", "warn"],
        ["whois/realtime", "$0.0015", "180ms", "2.1M", "ok"],
      ].map(([ep, pr, lat, ct, st]) => (
        <div key={ep} style={{ display: "grid", gridTemplateColumns: "2.4fr 1fr 1fr 1fr", gap: 16, padding: "14px 4px", borderBottom: "1px solid var(--rule)", fontFamily: "var(--mono)", fontSize: 12.5, alignItems: "center" }}>
          <span style={{ color: "var(--fg)" }}>{ep}</span>
          <span style={{ color: "var(--fg-dim)" }}>{pr}</span>
          <span style={{ color: "var(--fg-dim)" }}>{lat}</span>
          <span style={{ color: "var(--fg)" }}>
            <Status tone={st}>{ct}</Status>
          </span>
        </div>
      ))}
    </div>
    <div style={{ marginTop: 14, display: "flex", justifyContent: "space-between", fontFamily: "var(--mono)", fontSize: 10.5, color: "var(--fg-faint)", letterSpacing: "0.08em", textTransform: "uppercase" }}>
      <span>1,420 endpoints listed</span>
      <span>2% protocol fee</span>
    </div>
  </div>
);

/* Visual: Vault — wallet fleet */
const VisualVault = () => (
  <div className="diag scan" style={{ padding: 24, position: "relative" }}>
    <Crosshairs />
    <div className="coord-label" style={{ top: 12, left: 14 }}>FIG.V01</div>
    <div className="coord-label" style={{ top: 12, right: 14 }}>EXTODAN / VAULT</div>
    <div style={{ marginTop: 36, display: "grid", gridTemplateColumns: "1fr 1fr", gap: 12 }}>
      {[
        ["agent-001 · researcher", "8.42", 78],
        ["agent-002 · scraper", "12.10", 41],
        ["agent-003 · summarizer", "0.84", 12],
        ["agent-004 · analyst", "22.04", 92],
        ["agent-005 · planner", "5.61", 56],
        ["agent-006 · trader", "1.20", 8],
      ].map(([nm, bal, pct]) => (
        <div key={nm} style={{ border: "1px solid var(--rule)", padding: 14 }}>
          <div className="mono" style={{ fontSize: 11.5, color: "var(--fg)", marginBottom: 6 }}>{nm}</div>
          <div className="mono" style={{ fontSize: 18, color: "var(--fg)", letterSpacing: "-0.01em" }}>${bal}<span style={{ color: "var(--fg-faint)", fontSize: 11, marginLeft: 4 }}>USDC</span></div>
          <div style={{ marginTop: 10, height: 3, background: "var(--rule)" }}>
            <div style={{ width: `${pct}%`, height: "100%", background: "var(--fg)" }} />
          </div>
          <div className="mono" style={{ fontSize: 10, color: "var(--fg-faint)", marginTop: 6, letterSpacing: "0.06em", textTransform: "uppercase" }}>limit · {pct}% used</div>
        </div>
      ))}
    </div>
    <div style={{ marginTop: 18, padding: "12px 14px", border: "1px solid var(--rule)", display: "flex", justifyContent: "space-between", fontFamily: "var(--mono)", fontSize: 11, color: "var(--fg-dim)" }}>
      <span>FLEET TOTAL · $50.21 USDC</span>
      <span style={{ color: "var(--fg)" }}>+ auto top-up @ &lt; $5</span>
    </div>
  </div>
);

/* Visual: Muse — fee comparison */
const VisualMuse = () => (
  <div className="diag scan" style={{ padding: 32, position: "relative" }}>
    <Crosshairs />
    <div className="coord-label" style={{ top: 12, left: 14 }}>FIG.U01</div>
    <div className="coord-label" style={{ top: 12, right: 14 }}>EXTODAN / MUSE · CREATOR REVENUE %</div>
    <div style={{ marginTop: 50 }}>
      {[
        ["Substack", 90, "10% platform fee"],
        ["Patreon", 88, "up to 12% fee"],
        ["Gumroad", 90, "10% + processing"],
        ["Muse", 99, "1% protocol fee"],
      ].map(([name, pct, note], i) => (
        <div key={name} style={{ marginBottom: 22 }}>
          <div style={{ display: "flex", justifyContent: "space-between", marginBottom: 8 }}>
            <span style={{ fontFamily: "var(--sans)", fontSize: 14, color: name === "Muse" ? "var(--fg)" : "var(--fg-dim)", letterSpacing: "-0.01em" }}>{name}</span>
            <span className="mono" style={{ fontSize: 11, color: "var(--fg-faint)", letterSpacing: "0.06em", textTransform: "uppercase" }}>{note}</span>
          </div>
          <div style={{ height: 22, border: "1px solid var(--rule)", position: "relative" }}>
            <div style={{ width: `${pct}%`, height: "100%", background: name === "Muse" ? "var(--fg)" : "rgba(232,228,217,0.18)" }} />
            <span className="mono" style={{ position: "absolute", right: 8, top: 3, fontSize: 11, color: name === "Muse" ? "var(--bg)" : "var(--fg)", mixBlendMode: name === "Muse" ? "difference" : "normal" }}>{pct}% to creator</span>
          </div>
        </div>
      ))}
    </div>
    <div style={{ marginTop: 24, paddingTop: 16, borderTop: "1px solid var(--rule)", fontFamily: "var(--mono)", fontSize: 10.5, color: "var(--fg-faint)", letterSpacing: "0.06em", textTransform: "uppercase" }}>
      Per-piece pricing · no subscription · paid in USDC
    </div>
  </div>
);

/* Visual: Aegis — economics chart */
const VisualAegis = () => (
  <div className="diag scan" style={{ padding: 24, position: "relative" }}>
    <Crosshairs />
    <div className="coord-label" style={{ top: 12, left: 14 }}>FIG.A01</div>
    <div className="coord-label" style={{ top: 12, right: 14 }}>EXTODAN / AEGIS · COST CURVE</div>
    <div style={{ marginTop: 30, padding: "0 4px" }}>
      <svg viewBox="0 0 520 320" style={{ width: "100%", height: "auto" }} fill="none">
        {/* axes */}
        <line x1="40" y1="280" x2="500" y2="280" stroke="var(--fg-faint)" />
        <line x1="40" y1="20" x2="40" y2="280" stroke="var(--fg-faint)" />
        {/* grid */}
        {[60, 120, 180, 240].map((y) => (
          <line key={y} x1="40" y1={y} x2="500" y2={y} stroke="var(--rule)" />
        ))}
        {/* axis labels */}
        <text x="40" y="12" fill="var(--fg-faint)" fontFamily="var(--mono)" fontSize="9">$ COST</text>
        <text x="490" y="298" fill="var(--fg-faint)" fontFamily="var(--mono)" fontSize="9" textAnchor="end">REQUESTS →</text>
        {[1e3, 1e5, 1e7].map((v, i) => (
          <text key={v} x={80 + i * 200} y="298" fill="var(--fg-faint)" fontFamily="var(--mono)" fontSize="9" textAnchor="middle">{v >= 1e6 ? `${v / 1e6}M` : `${v / 1e3}k`}</text>
        ))}
        <text x="34" y="60" fill="var(--fg-faint)" fontFamily="var(--mono)" fontSize="9" textAnchor="end">$10k</text>
        <text x="34" y="180" fill="var(--fg-faint)" fontFamily="var(--mono)" fontSize="9" textAnchor="end">$100</text>
        <text x="34" y="280" fill="var(--fg-faint)" fontFamily="var(--mono)" fontSize="9" textAnchor="end">$0.01</text>
        {/* legitimate user line — flat low */}
        <path d="M 40 268 L 500 264" stroke="var(--ok)" strokeWidth="1.4" />
        <text x="380" y="258" fill="var(--ok)" fontFamily="var(--mono)" fontSize="10">LEGITIMATE → trivial</text>
        {/* attacker curve — exponential */}
        <path d="M 40 278 Q 200 270, 320 200 T 500 30" stroke="var(--err)" strokeWidth="1.6" />
        <text x="360" y="100" fill="var(--err)" fontFamily="var(--mono)" fontSize="10">ATTACKER → economic floor</text>
        {/* threshold line */}
        <line x1="380" y1="280" x2="380" y2="20" stroke="var(--warn)" strokeDasharray="3 3" />
        <text x="384" y="34" fill="var(--warn)" fontFamily="var(--mono)" fontSize="10">attack irrational</text>
      </svg>
    </div>
    <div style={{ marginTop: 12, paddingTop: 12, borderTop: "1px solid var(--rule)", display: "flex", justifyContent: "space-between", fontFamily: "var(--mono)", fontSize: 10.5, color: "var(--fg-faint)", letterSpacing: "0.06em", textTransform: "uppercase" }}>
      <span>$0.001 / request</span>
      <span>10M reqs = $1,000 floor</span>
    </div>
  </div>
);

const Products = () => (
  <section id="products" style={{ position: "relative" }}>
    <div className="shell" style={{ padding: "120px 40px 40px" }}>
      <Marker section="02" label="PLATFORM" />
      <h2 className="h-section reveal" style={{ marginTop: 28, marginBottom: 24 }}>Four products.<br />One protocol.</h2>
      <p className="lede reveal" style={{ marginBottom: 0 }}>
        Each piece works alone. Together they cover discovery, payment authorization, content monetization, and abuse prevention — every layer of x402 in production.
      </p>
    </div>

    <ProductRow
      idx={1}
      name="Extodan"
      slug="marketplace"
      oneLine="The marketplace for x402-gated APIs. Publish an endpoint, set a price per call, get paid by humans and agents alike."
      problem="Building monetized APIs today means stitching together Stripe, accounts, billing, and rate limits before you write a line of business logic."
      body="Wrap your API with the SDK, set a price in USDC, list it. The marketplace handles discovery, documentation, reliability monitoring, and analytics. Extodan takes 2% of every payment — there is no monthly fee, no tier system, no quota."
      points={[
        { k: "Pricing model", v: "Per-call USDC, set by publisher" },
        { k: "Platform fee", v: "2% of settled payments" },
        { k: "Onboarding", v: "Wrap, set price, ship — no billing setup" },
        { k: "Audience", v: "Human developers + autonomous agents" },
      ]}
      visual={<VisualMarketplace />}
      href="marketplace.html"
    />

    <ProductRow
      idx={2}
      name="Extodan Vault"
      slug="vault"
      oneLine="Wallet infrastructure for AI agent fleets. Provision, fund, limit, and audit thousands of agent wallets through a single API."
      problem="Every agent that pays for an x402 service needs its own funded wallet. At one agent that's a person's problem. At a thousand it's a finance team's problem."
      body="Vault gives organizations programmatic wallets per agent, with spending limits, automatic top-ups, and a complete audit trail. The same primitives a CFO expects from a payment processor — but exposed as API, not a portal."
      points={[
        { k: "Provisioning", v: "POST /agents → funded wallet in <1s" },
        { k: "Spend controls", v: "Per-agent limits, allowlists, budgets" },
        { k: "Audit", v: "Every payment, every agent, signed and logged" },
        { k: "Top-ups", v: "Automatic from treasury when balance &lt; threshold" },
      ]}
      visual={<VisualVault />}
      href="vault.html"
    />

    <ProductRow
      idx={3}
      name="Extodan Muse"
      slug="muse"
      oneLine="Publishing built on x402. Creators charge per piece, keep 99%, and never ask a reader to subscribe or hand over a card."
      problem="Substack takes 10%. Patreon takes up to 12%. Both require subscriptions, accounts, and a reader who has decided to commit before they've read a word."
      body="Muse looks like a normal publishing tool. The crypto rails are invisible. A creator writes, sets a price per piece, and readers pay only for what they read. Settlement is on x402, so the platform fee is 1% — the rest goes to the creator."
      points={[
        { k: "Platform fee", v: "1% — vs. 10–12% on existing platforms" },
        { k: "Reader experience", v: "No subscription, no account, pay-per-piece" },
        { k: "Creator experience", v: "Standard editor, standard analytics" },
        { k: "Payouts", v: "Direct to creator wallet, immediate" },
      ]}
      visual={<VisualMuse />}
      href="muse.html"
    />

    <ProductRow
      idx={4}
      name="Extodan Aegis"
      slug="aegis"
      oneLine="API protection by economics, not rules. Charge a fraction of a cent per request — trivial for users, ruinous for abusers."
      problem="Rate limiting and IP blocking are arms races against attackers who eventually find a way through. The web spends billions on a defense that is structurally insufficient."
      body="Aegis sits in front of any existing API. You set a per-request price. Real users and agents pay the trivial fee and pass through. A bot making ten million requests faces a thousand-dollar cost floor — the attack stops being rational. Payments route into your Vault."
      points={[
        { k: "Defense model", v: "Economic, not heuristic" },
        { k: "Latency overhead", v: "&lt; 12ms gateway" },
        { k: "Integration", v: "DNS or reverse-proxy, no code changes" },
        { k: "Revenue", v: "All payments routed to your Vault wallet" },
      ]}
      visual={<VisualAegis />}
      href="aegis.html"
    />
  </section>
);

Object.assign(window, { Products, VisualMarketplace, VisualVault, VisualMuse, VisualAegis });
