// Non-hero sections for Ninja Typer
const { useState: useState2, useEffect: useEffect2 } = React;

// ————————————————————————————————————————————————————————————
// Logo bar — placeholder Mac apps where it works
// ————————————————————————————————————————————————————————————
const APPS = [
  { name: "Messages", kind: "messages" },
  { name: "Mail", kind: "mail" },
  { name: "Slack", kind: "slack" },
  { name: "Notes", kind: "notes" },
  { name: "VS Code", kind: "vscode" },
  { name: "Notion", kind: "notion" },
  { name: "Figma", kind: "figma" },
  { name: "Chrome", kind: "chrome" },
  { name: "Terminal", kind: "terminal" },
  { name: "Linear", kind: "linear" },
  { name: "Discord", kind: "discord" },
  { name: "Safari", kind: "safari" },
];

function LogoBar() {
  return (
    <section className="section logos">
      <div className="logos-label">
        <span className="logos-dot" />
        Works in every text field on your Mac
      </div>
      <div className="logos-track">
        <div className="logos-row">
          {[...APPS, ...APPS].map((a, i) => (
            <div key={i} className="logo-chip">
              <div className="logo-chip-glyph"><AppIcon kind={a.kind} /></div>
              <span>{a.name}</span>
            </div>
          ))}
        </div>
      </div>
    </section>
  );
}

// ————————————————————————————————————————————————————————————
// How it works — 3 steps with animated illustration
// ————————————————————————————————————————————————————————————
function HowItWorks() {
  const [active, setActive] = useState2(0);
  const [paused, setPaused] = useState2(false);
  useEffect2(() => {
    if (paused) return;
    const id = setInterval(() => setActive(a => (a + 1) % 3), 4000);
    return () => clearInterval(id);
  }, [paused]);

  const steps = [
    {
      num: "01",
      title: "Hold fn",
      desc: "Press and hold fn, or rebind it to whatever your thumb likes. No window opens, nothing interrupts. The ninja is simply listening.",
    },
    {
      num: "02",
      title: "Speak your mind",
      desc: "Ramble, backtrack, pause to sip coffee. The mic only listens while the key is down, and the ninja never rushes you.",
    },
    {
      num: "03",
      title: "Release. It's typed.",
      desc: "Lift your finger and the clean version lands wherever your cursor is. Email, code review, search bar, spicy group chat.",
    },
  ];

  return (
    <section className="section how" id="how">
      <div className="section-head">
        <div className="section-eyebrow">How it works</div>
        <h2 className="section-title">You do three things. Barely.</h2>
        <p className="section-sub">The engine up top does the heavy lifting. This is your entire share of the work.</p>
      </div>
      <div className="how-grid" onMouseLeave={() => setPaused(false)}>
        {steps.map((s, i) => (
          <div
            key={i}
            className={`how-card ${active === i ? "active" : ""}`}
            onMouseEnter={() => { setActive(i); setPaused(true); }}
          >
            <div className="how-num">{s.num}</div>
            <div className="how-illu">
              <StepIllustration index={i} active={active === i} />
            </div>
            <h3 className="how-title">{s.title}</h3>
            <p className="how-desc">{s.desc}</p>
            {active === i && !paused && <div className="how-progress" key={`p${i}`} />}
          </div>
        ))}
      </div>
    </section>
  );
}

function StepIllustration({ index, active }) {
  if (index === 0) {
    // Hand holding fn key
    return (
      <svg viewBox="0 0 240 140" className="step-svg" aria-hidden>
        <rect x="10" y="10" width="220" height="120" rx="10" fill="var(--paper-2)" stroke="var(--ink)" strokeWidth="1.5" />
        {/* keyboard grid */}
        {Array.from({ length: 5 }).map((_, col) => (
          Array.from({ length: 3 }).map((_, row) => (
            <rect key={`${col}-${row}`}
              x={22 + col * 42} y={22 + row * 30}
              width="36" height="26" rx="4"
              fill="var(--paper)" stroke="var(--ink)" strokeWidth="1.2"
            />
          ))
        ))}
        {/* fn key pressed */}
        <rect x="22" y="82" width="36" height="26" rx="4" fill={active ? "var(--accent)" : "var(--paper)"} stroke="var(--ink)" strokeWidth="1.8" />
        <text x="40" y="99" textAnchor="middle" fontFamily="var(--font-mono)" fontSize="11" fontWeight="700" fill="var(--ink)">fn</text>
        {/* pulse */}
        {active && (
          <circle cx="40" cy="95" r="22" fill="none" stroke="var(--accent)" strokeWidth="2" className="pulse-ring" />
        )}
      </svg>
    );
  }
  if (index === 1) {
    // Waveform into speech bubble
    return (
      <svg viewBox="0 0 240 140" className="step-svg" aria-hidden>
        {/* head silhouette */}
        <circle cx="48" cy="70" r="28" fill="var(--ink)" />
        <rect x="30" y="64" width="36" height="8" rx="4" fill="var(--paper)" />
        {/* waves */}
        {[0,1,2,3,4].map(i => (
          <path key={i}
            d={`M${90 + i*8} ${70 - 20 - i*2} Q ${94 + i*8} 70 ${90 + i*8} ${70 + 20 + i*2}`}
            fill="none" stroke="var(--accent)" strokeOpacity={active ? 1 - i*0.15 : 0.25} strokeWidth="2" strokeLinecap="round"
            className={active ? "wave-anim" : ""}
            style={{ animationDelay: `${i * 120}ms` }}
          />
        ))}
        {/* bubble */}
        <rect x="150" y="46" width="80" height="48" rx="8" fill="var(--paper-2)" stroke="var(--ink)" strokeWidth="1.5" />
        <path d="M150 70 L144 78 L150 82" fill="var(--paper-2)" stroke="var(--ink)" strokeWidth="1.5" strokeLinejoin="round" />
        <line x1="160" y1="60" x2="218" y2="60" stroke="var(--ink)" strokeWidth="2" opacity="0.7" />
        <line x1="160" y1="70" x2="210" y2="70" stroke="var(--ink)" strokeWidth="2" opacity="0.5" />
        <line x1="160" y1="80" x2="200" y2="80" stroke="var(--ink)" strokeWidth="2" opacity="0.3" />
      </svg>
    );
  }
  // step 3: shuriken flying into text field
  return (
    <svg viewBox="0 0 240 140" className="step-svg" aria-hidden>
      {/* text field */}
      <rect x="60" y="50" width="170" height="48" rx="6" fill="var(--paper)" stroke="var(--ink)" strokeWidth="1.5" />
      <text x="72" y="80" fontFamily="var(--font-mono)" fontSize="12" fill="var(--ink)">Got it, sending now.</text>
      <rect x="218" y="58" width="2" height="32" fill="var(--ink)" className="caret-blink" />
      {/* shuriken trail */}
      <line x1="10" y1="76" x2="55" y2="74" stroke="var(--ink)" strokeWidth="1.2" strokeDasharray="3 4" opacity="0.5" />
      <g transform={`translate(${active ? 44 : 14} 74)`} className={active ? "shur-fly" : ""}>
        <path d="M0 -10 L3 -3 L10 0 L3 3 L0 10 L-3 3 L-10 0 L-3 -3 Z" fill="var(--accent)" stroke="var(--ink)" strokeWidth="1.4" strokeLinejoin="round" />
      </g>
    </svg>
  );
}

// ————————————————————————————————————————————————————————————
// Stylized app icons — original geometric drawings in our house style
// all share: bold 1.5px ink stroke, flat fills, slight ninja flair
// ————————————————————————————————————————————————————————————
function AppIcon({ kind }) {
  const S = 48;
  const common = { width: S, height: S, viewBox: "0 0 48 48", "aria-hidden": true };
  switch (kind) {
    case "mail":
      return (
        <svg {...common}>
          <rect x="6" y="12" width="36" height="26" rx="4" fill="var(--accent-soft)" stroke="var(--ink)" strokeWidth="1.8" />
          <path d="M6 14 L24 28 L42 14" fill="none" stroke="var(--ink)" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round" />
          <circle cx="36" cy="14" r="4" fill="var(--accent)" stroke="var(--ink)" strokeWidth="1.5" />
        </svg>
      );
    case "messages":
      return (
        <svg {...common}>
          <path d="M8 10 H38 A4 4 0 0 1 42 14 V30 A4 4 0 0 1 38 34 H18 L10 40 V34 A2 2 0 0 1 8 32 V14 A4 4 0 0 1 12 10 Z" fill="var(--accent-2-soft)" stroke="var(--ink)" strokeWidth="1.8" strokeLinejoin="round" />
          <circle cx="17" cy="22" r="2" fill="var(--ink)" />
          <circle cx="24" cy="22" r="2" fill="var(--ink)" />
          <circle cx="31" cy="22" r="2" fill="var(--ink)" />
        </svg>
      );
    case "slack":
      return (
        <svg {...common}>
          <rect x="10" y="10" width="28" height="28" rx="6" fill="var(--paper)" stroke="var(--ink)" strokeWidth="1.8" />
          <rect x="15" y="19" width="18" height="3" rx="1.5" fill="var(--accent)" />
          <rect x="15" y="26" width="14" height="3" rx="1.5" fill="var(--accent-2)" />
          <rect x="19" y="14" width="3" height="20" rx="1.5" fill="var(--ink)" transform="rotate(90 20.5 24)" opacity="0" />
          <rect x="18" y="14" width="3" height="20" rx="1.5" fill="var(--ink)" />
          <rect x="27" y="14" width="3" height="20" rx="1.5" fill="var(--ink)" />
        </svg>
      );
    case "vscode":
      return (
        <svg {...common}>
          <rect x="6" y="8" width="36" height="32" rx="4" fill="var(--ink)" stroke="var(--ink)" strokeWidth="1.8" />
          <text x="24" y="30" textAnchor="middle" fontFamily="var(--font-mono)" fontSize="14" fontWeight="700" fill="var(--accent)">&lt;/&gt;</text>
          <circle cx="11" cy="13" r="1.2" fill="var(--accent-2)" />
          <circle cx="15" cy="13" r="1.2" fill="var(--accent)" />
          <circle cx="19" cy="13" r="1.2" fill="var(--paper)" opacity="0.4" />
        </svg>
      );
    case "notion":
      return (
        <svg {...common}>
          <rect x="8" y="8" width="32" height="32" rx="4" fill="var(--paper)" stroke="var(--ink)" strokeWidth="1.8" />
          <path d="M15 15 V33 M15 15 L29 33 M29 15 V33" fill="none" stroke="var(--ink)" strokeWidth="2.4" strokeLinecap="round" strokeLinejoin="round" />
          <rect x="8" y="8" width="32" height="6" fill="var(--accent-soft)" stroke="var(--ink)" strokeWidth="1.8" />
        </svg>
      );
    case "figma":
      return (
        <svg {...common}>
          <circle cx="19" cy="14" r="6" fill="var(--accent)" stroke="var(--ink)" strokeWidth="1.8" />
          <circle cx="29" cy="14" r="6" fill="var(--accent-2)" stroke="var(--ink)" strokeWidth="1.8" />
          <circle cx="19" cy="24" r="6" fill="var(--paper)" stroke="var(--ink)" strokeWidth="1.8" />
          <circle cx="29" cy="24" r="6" fill="var(--ink)" />
          <circle cx="19" cy="34" r="6" fill="var(--accent-soft)" stroke="var(--ink)" strokeWidth="1.8" />
        </svg>
      );
    case "linear":
      return (
        <svg {...common}>
          <circle cx="24" cy="24" r="17" fill="var(--paper)" stroke="var(--ink)" strokeWidth="1.8" />
          <path d="M14 14 L34 34 M10 22 L26 38 M22 10 L38 26" stroke="var(--ink)" strokeWidth="2" strokeLinecap="round" />
        </svg>
      );
    case "terminal":
      return (
        <svg {...common}>
          <rect x="6" y="10" width="36" height="28" rx="4" fill="var(--ink)" stroke="var(--ink)" strokeWidth="1.8" />
          <path d="M12 20 L17 24 L12 28" fill="none" stroke="var(--accent)" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" />
          <rect x="19" y="27" width="12" height="2" fill="var(--paper)" />
        </svg>
      );
    case "safari":
      return (
        <svg {...common}>
          <circle cx="24" cy="24" r="17" fill="var(--paper)" stroke="var(--ink)" strokeWidth="1.8" />
          <path d="M24 14 L27 22 L34 24 L27 26 L24 34 L21 26 L14 24 L21 22 Z" fill="var(--accent)" stroke="var(--ink)" strokeWidth="1.4" strokeLinejoin="round" />
          <circle cx="24" cy="24" r="1.5" fill="var(--ink)" />
        </svg>
      );
    case "discord":
      return (
        <svg {...common}>
          <path d="M10 14 Q14 10 20 10 L28 10 Q34 10 38 14 L40 32 Q36 36 30 36 L28 32 L20 32 L18 36 Q12 36 8 32 Z" fill="var(--accent-2-soft)" stroke="var(--ink)" strokeWidth="1.8" strokeLinejoin="round" />
          <ellipse cx="19" cy="23" rx="2.5" ry="3.5" fill="var(--ink)" />
          <ellipse cx="29" cy="23" rx="2.5" ry="3.5" fill="var(--ink)" />
        </svg>
      );
    case "spotlight":
      return (
        <svg {...common}>
          <circle cx="21" cy="21" r="11" fill="var(--paper)" stroke="var(--ink)" strokeWidth="1.8" />
          <circle cx="21" cy="21" r="5" fill="var(--accent)" stroke="var(--ink)" strokeWidth="1.4" />
          <path d="M30 30 L40 40" stroke="var(--ink)" strokeWidth="3" strokeLinecap="round" />
        </svg>
      );
    case "chatgpt":
      return (
        <svg {...common}>
          <circle cx="24" cy="24" r="16" fill="var(--ink)" />
          <path d="M24 14 L32 19 V29 L24 34 L16 29 V19 Z" fill="none" stroke="var(--accent)" strokeWidth="1.8" strokeLinejoin="round" />
          <circle cx="24" cy="24" r="3" fill="var(--accent)" />
        </svg>
      );
    case "notes":
      return (
        <svg {...common}>
          <rect x="10" y="8" width="28" height="32" rx="3" fill="var(--accent-soft)" stroke="var(--ink)" strokeWidth="1.8" />
          <line x1="15" y1="18" x2="33" y2="18" stroke="var(--ink)" strokeWidth="1.5" />
          <line x1="15" y1="24" x2="33" y2="24" stroke="var(--ink)" strokeWidth="1.5" />
          <line x1="15" y1="30" x2="27" y2="30" stroke="var(--ink)" strokeWidth="1.5" />
          <path d="M10 12 L38 12" stroke="var(--accent)" strokeWidth="3" />
        </svg>
      );
    case "chrome":
      return (
        <svg {...common}>
          <circle cx="24" cy="24" r="17" fill="var(--paper)" stroke="var(--ink)" strokeWidth="1.8" />
          <circle cx="24" cy="24" r="7" fill="var(--accent-soft)" stroke="var(--ink)" strokeWidth="1.5" />
          <path d="M24 7 L24 17 M11 32 L20 27 M37 32 L28 27" stroke="var(--ink)" strokeWidth="1.8" strokeLinecap="round" />
        </svg>
      );
    default:
      return null;
  }
}

// ————————————————————————————————————————————————————————————
// Integrations — two sliding marquee rows, opposite directions
// ————————————————————————————————————————————————————————————
function Integrations() {
  const rowA = [
    { name: "Mail", kind: "mail" },
    { name: "Messages", kind: "messages" },
    { name: "Slack", kind: "slack" },
    { name: "VS Code", kind: "vscode" },
    { name: "Notion", kind: "notion" },
    { name: "Figma", kind: "figma" },
    { name: "Linear", kind: "linear" },
  ];
  const rowB = [
    { name: "Terminal", kind: "terminal" },
    { name: "Safari", kind: "safari" },
    { name: "Discord", kind: "discord" },
    { name: "Spotlight", kind: "spotlight" },
    { name: "ChatGPT", kind: "chatgpt" },
    { name: "Notes", kind: "notes" },
    { name: "Chrome", kind: "chrome" },
  ];

  const renderTile = (a, i) => (
    <div key={i} className="integ-tile">
      <div className="integ-icon"><AppIcon kind={a.kind} /></div>
      <div className="integ-name">{a.name}</div>
      <div className="integ-check">
        <svg width="10" height="10" viewBox="0 0 10 10" aria-hidden>
          <path d="M1.5 5.5L4 8L8.5 2.5" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round" fill="none" />
        </svg>
      </div>
    </div>
  );

  return (
    <section className="section integrations" id="integrations">
      <div className="section-head">
        <div className="section-eyebrow">Works everywhere</div>
        <h2 className="section-title">Any text field. No plugins.</h2>
        <p className="section-sub">Ninja Typer works at the OS level on macOS, so it types into anything with a cursor. Native apps, web apps, search bars, command palettes. If you can click into it, the ninja can type into it.</p>
      </div>

      <div className="integ-marquee">
        <div className="integ-row integ-row-left">
          {[...rowA, ...rowA, ...rowA].map(renderTile)}
        </div>
        <div className="integ-row integ-row-right">
          {[...rowB, ...rowB, ...rowB].map(renderTile)}
        </div>

        <div className="integ-catchall">
          <div className="integ-catchall-inner">
            <Shuriken size={32} />
            <div>
              <div className="integ-catchall-title">+ every other app on your Mac</div>
              <div className="integ-catchall-sub">if it accepts keystrokes, we type into it</div>
            </div>
          </div>
        </div>
      </div>
    </section>
  );
}

// ————————————————————————————————————————————————————————————
// Pricing
// ————————————————————————————————————————————————————————————
function Pricing() {
  return (
    <section className="section pricing" id="pricing">
      <div className="section-head">
        <div className="section-eyebrow">Pricing</div>
        <h2 className="section-title">Zero dollars. For now.</h2>
        <p className="section-sub">Ninja Typer is free during early access. You bring your own Groq API key (which has a free tier), plug it in during setup, and the ninja gets to work. Paid plans will arrive one day; early users will be treated kindly. No trial countdown, no "talk to sales".</p>
      </div>

      <div className="price-hero">
        <div className="price-hero-left">
          <div className="price-big">
            <span className="price-currency">$</span>
            <span className="price-number">0</span>
            <span className="price-suffix">
              <span>/early access</span>
              <span className="price-suffix-sub">the ninja has no use for money (yet)</span>
            </span>
          </div>

          <a className="btn btn-primary btn-large btn-block" href={window.NT_DOWNLOAD_URL} download>
            Download for Mac
            <svg width="14" height="14" viewBox="0 0 14 14" fill="none" aria-hidden>
              <path d="M7 2v8M3 7l4 4 4-4" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round"/>
            </svg>
          </a>
          <div className="price-foot">macOS 14+ · setup takes about five minutes, most of it spent admiring the onboarding</div>
        </div>

        <div className="price-hero-right">
          <div className="price-anchor">
            <div className="price-anchor-num">BYOK</div>
            <div className="price-anchor-label">bring your own key</div>
            <div className="price-anchor-math">
              Grab a free Groq API key, paste it once during setup,<br />
              and your dictation runs on your own account. Your key, your data.
            </div>
          </div>

          <ul className="price-included">
            <li>
              <svg width="14" height="14" viewBox="0 0 14 14" aria-hidden>
                <path d="M2 7.5L5.5 11L12 3.5" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" fill="none" />
              </svg>
              57 languages, custom dictionary
            </li>
            <li>
              <svg width="14" height="14" viewBox="0 0 14 14" aria-hidden>
                <path d="M2 7.5L5.5 11L12 3.5" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" fill="none" />
              </svg>
              Writing styles: professional, casual, technical
            </li>
            <li>
              <svg width="14" height="14" viewBox="0 0 14 14" aria-hidden>
                <path d="M2 7.5L5.5 11L12 3.5" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" fill="none" />
              </svg>
              Local mode: on-device models, fully offline
            </li>
            <li>
              <svg width="14" height="14" viewBox="0 0 14 14" aria-hidden>
                <path d="M2 7.5L5.5 11L12 3.5" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" fill="none" />
              </svg>
              Every macOS app, every text field
            </li>
          </ul>
        </div>
      </div>
    </section>
  );
}

// ————————————————————————————————————————————————————————————
// Footer CTA
// ————————————————————————————————————————————————————————————
function FooterCTA() {
  return (
    <section className="footer-cta">
      <div className="footer-cta-inner">
        {/* big shuriken */}
        <div className="footer-shuriken">
          <svg viewBox="0 0 200 200" aria-hidden>
            <g fill="var(--accent)" stroke="var(--ink)" strokeWidth="3" strokeLinejoin="round">
              <path d="M100 10 L120 80 L190 100 L120 120 L100 190 L80 120 L10 100 L80 80 Z" />
            </g>
            <circle cx="100" cy="100" r="12" fill="var(--paper)" stroke="var(--ink)" strokeWidth="3" />
          </svg>
        </div>

        <PlatformBadge light />
        <h2 className="footer-cta-title">Ready to retire<br />your keyboard?</h2>
        <p className="footer-cta-sub">Free during early access. Your fingers will send a thank-you note. Probably dictated.</p>
        <div className="footer-cta-buttons">
          <a className="btn btn-primary btn-large" href={window.NT_DOWNLOAD_URL} download>
            Download for Mac
            <svg width="14" height="14" viewBox="0 0 14 14" fill="none" aria-hidden>
              <path d="M7 2v8M3 7l4 4 4-4" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round"/>
            </svg>
          </a>
        </div>
        <div className="footer-cta-meta">
          <span>early access</span>
          <span>·</span>
          <span>bring your own Groq key</span>
        </div>
      </div>

      <footer className="site-footer">
        <div className="site-footer-left">
          <div className="wordmark">
            <Shuriken size={22} spin={false} />
            <span>Ninja Typer</span>
          </div>
          <span className="footer-copy">© 2026 Ninja Typer Labs. Made with silent keystrokes.</span>
        </div>
        <div className="site-footer-links">
          <a href="privacy.html">Privacy</a>
          <a href="terms.html">Terms</a>
          <a href="privacy.html#security">Security</a>
          <a href="blog.html">Articles</a>
          <a href="changelog.html">Changelog</a>
          <a href="licenses.html">Licenses</a>
        </div>
      </footer>

      {/* giant wordmark, clipped at the fold — the last thing you see */}
      <div className="footer-giant" aria-hidden>
        <span>ninja</span>
        <Shuriken size={120} spin={false} />
        <span>typer</span>
      </div>
    </section>
  );
}

Object.assign(window, { LogoBar, HowItWorks, Integrations, Pricing, FooterCTA });
