/* homeparts.jsx — home page enrichment: LoopHero (water-world loop, one charge,
   parts animate as it arrives), ShelfBand (nine parts, glyphs animate as the
   charge passes), FinaleBand (certificate ending). Styles in home.css. */

function HomeLoopHero() {
  const chargePath = "M40 165 L40 76 Q40 50 66 50 L394 50 Q420 50 420 76 L420 254 Q420 280 394 280 L66 280 Q40 280 40 254 Z";
  return (
    <div className="loopvis" aria-hidden="true">
      <svg viewBox="0 0 460 330" aria-hidden="true">
        <rect x="40" y="50" width="380" height="230" rx="26" fill="none" stroke="var(--rule-strong)" strokeWidth="7" />
        <rect x="14" y="120" width="52" height="90" rx="6" fill="var(--bg)" stroke="var(--water-deep)" strokeWidth="3" />
        <g className="lvb lvbPump">
          <rect x="18" y="146" width="44" height="60" fill="var(--water)" opacity="0.45" />
          <line x1="20" y1="142" x2="60" y2="142" stroke="var(--water-deep)" strokeWidth="3" />
        </g>
        <text x="40" y="235" textAnchor="middle" fontFamily="IBM Plex Mono" fontSize="11" fill="var(--water-deep)">PUMP</text>
        <path className="lvb lvbPinch" d="M210 42 q20 -18 40 0" fill="none" stroke="var(--water-deep)" strokeWidth="3" />
        <text x="230" y="82" textAnchor="middle" fontFamily="IBM Plex Mono" fontSize="11" fill="var(--water-deep)">PINCH</text>
        <g className="lvb lvbWheel">
          <circle cx="420" cy="165" r="26" fill="var(--bg)" stroke="var(--water-deep)" strokeWidth="3" />
          <line x1="420" y1="141" x2="420" y2="189" stroke="var(--water-deep)" strokeWidth="2.5" />
          <line x1="396" y1="165" x2="444" y2="165" stroke="var(--water-deep)" strokeWidth="2.5" />
          <line x1="403" y1="148" x2="437" y2="182" stroke="var(--water-deep)" strokeWidth="2.5" />
          <line x1="437" y1="148" x2="403" y2="182" stroke="var(--water-deep)" strokeWidth="2.5" />
        </g>
        <text x="420" y="218" textAnchor="middle" fontFamily="IBM Plex Mono" fontSize="11" fill="var(--water-deep)">WHEEL</text>
        <circle className="lv-dotc" r="7" fill="var(--water-soft)">
          <animateMotion dur="6s" repeatCount="indefinite" path={chargePath} />
        </circle>
      </svg>
      <span className="lv-mode">pressure pushes flow — scroll, and watch it become a circuit</span>
    </div>
  );
}

const SHELF_PARTS = [
  { name: "Battery", tag: "the pump", g: <g className="glyph ga gaPush"><line x1="2" y1="20" x2="18" y2="20" /><line x1="18" y1="8" x2="18" y2="32" /><line x1="26" y1="14" x2="26" y2="26" /><line x1="26" y1="20" x2="50" y2="20" /></g> },
  { name: "Resistor", tag: "the pinch", g: <path className="glyph ga gaShake" d="M2 20 h8 l4 -9 l6 18 l6 -18 l6 18 l6 -18 l4 9 h8" /> },
  { name: "LED", tag: "the wheel", g: <g className="glyph"><line x1="2" y1="20" x2="16" y2="20" /><path d="M16 10 L34 20 L16 30 Z" /><line x1="34" y1="10" x2="34" y2="30" /><line x1="34" y1="20" x2="50" y2="20" /><g className="ga gaRays"><path d="M30 8 l6 -6 M36 12 l6 -6" strokeWidth="1.6" /></g></g> },
  { name: "Capacitor", tag: "the bucket", g: <g className="glyph"><line x1="2" y1="20" x2="22" y2="20" /><g className="ga gaFill"><line x1="22" y1="7" x2="22" y2="33" /><line x1="30" y1="7" x2="30" y2="33" /></g><line x1="30" y1="20" x2="50" y2="20" /></g> },
  { name: "Switch", tag: "the valve", g: <g className="glyph"><line x1="2" y1="20" x2="14" y2="20" /><circle cx="17" cy="20" r="2.6" /><line className="ga gaLever" x1="19" y1="19" x2="36" y2="8" /><circle cx="38" cy="20" r="2.6" /><line x1="41" y1="20" x2="50" y2="20" /></g> },
  { name: "Transistor", tag: "the gate", g: <g className="glyph ga gaPulse"><circle cx="27" cy="20" r="13" /><line x1="21" y1="12" x2="21" y2="28" /><line x1="2" y1="20" x2="21" y2="20" /><line x1="21" y1="16" x2="34" y2="7" /><line x1="21" y1="24" x2="34" y2="33" /><path d="M29 29 l5 4 l-6 1 Z" fill="var(--ink)" /></g> },
  { name: "Diode", tag: "one-way door", g: <g className="glyph"><line x1="2" y1="20" x2="16" y2="20" /><path className="ga gaNudge" d="M16 10 L34 20 L16 30 Z" /><line x1="34" y1="10" x2="34" y2="30" /><line x1="34" y1="20" x2="50" y2="20" /></g> },
  { name: "Inductor", tag: "the flywheel", g: <path className="glyph ga gaSquish" d="M2 20 h6 a5 5 0 0 1 10 0 a5 5 0 0 1 10 0 a5 5 0 0 1 10 0 a5 5 0 0 1 10 0 h4" /> },
  { name: "The 555", tag: "the metronome", g: <g className="glyph"><rect x="12" y="6" width="28" height="28" rx="3" /><line x1="6" y1="12" x2="12" y2="12" /><line x1="6" y1="20" x2="12" y2="20" /><line x1="6" y1="28" x2="12" y2="28" /><line x1="40" y1="12" x2="46" y2="12" /><line x1="40" y1="20" x2="46" y2="20" /><line x1="40" y1="28" x2="46" y2="28" /><text className="ga gaBlink" x="26" y="24" textAnchor="middle" fontFamily="IBM Plex Mono" fontSize="9" fill="var(--ink)" stroke="none">555</text></g> },
];

function ShelfBand({ kids }) {
  return (
    <section className="shelf-band">
      <div className="eyebrow">the cast · nine parts, one course</div>
      <h2 className="shelf-h">Every part on this shelf, <em>understood — then wired.</em></h2>
      <div className="shelf-row">
        <div className="shelf-wire"></div>
        <div className="shelf-charge"></div>
        {SHELF_PARTS.map((p, i) => (
          <div className="shelf-item" style={{ "--i": i }} key={p.name}>
            <span className="glyphbox"><svg width="52" height="40" viewBox="0 0 52 40" aria-hidden="true">{p.g}</svg></span>
            <b>{p.name}</b>
            <i>{p.tag}</i>
          </div>
        ))}
      </div>
      <p className="hg-facts" style={{ marginTop: 20 }}>
        {kids
          ? "Each one gets the same treatment: watch it as water, guess what it does, then build it for real."
          : "Each one gets the same treatment: watch it as water, predict what it does, then wire it on a real breadboard."}
        {" "}Hover any part — each gets its own chapter.
      </p>
    </section>
  );
}

const HG_ICONS = [
  <svg width="44" height="30" viewBox="0 0 44 30" key="i0" aria-hidden="true"><path className="glyph" d="M2 15 h6 l3 -7 l5 14 l5 -14 l5 14 l3 -7 h13" /></svg>,
  <svg width="44" height="30" viewBox="0 0 44 30" key="i1" aria-hidden="true"><g className="glyph"><rect x="4" y="6" width="36" height="18" rx="3" />{[12, 18, 24, 30].map(x => [12, 18].map(y => <circle key={x + "-" + y} cx={x} cy={y} r="1.4" fill="var(--ink)" stroke="none" />))}</g></svg>,
  <svg width="44" height="30" viewBox="0 0 44 30" key="i2" aria-hidden="true"><g className="glyph"><rect x="3" y="4" width="38" height="22" rx="3" /><path d="M8 18 l6 -8 l5 6 l6 -10 l5 8 l6 -4" stroke="var(--current)" /></g></svg>,
  <svg width="44" height="30" viewBox="0 0 44 30" key="i3" aria-hidden="true"><g className="glyph"><path d="M18 26 L21 8 L23 8 L26 26 Z" /><circle cx="22" cy="5" r="2.6" fill="var(--current)" stroke="none" /></g></svg>,
];

function FinaleBand({ resumeHref, ctaLabel }) {
  return (
    <section className="fin-band">
      <div className="fin-grid">
        <div>
          <div className="eyebrow" style={{ marginBottom: 10 }}>and when you're done</div>
          <h3 className="fin-h">Leave with a device <em>and the paper to prove it.</em></h3>
          <p className="fin-p">
            Pass the Level 1 exam for your Apprentice certificate; wire the beacon
            and pass Level 2 for Engineer. Free, printable, earned — no account needed.
          </p>
          <div className="home-cta-row">
            <a href={resumeHref} className="cta cta-primary">{ctaLabel} →</a>
            <a href="map.html" className="cta cta-secondary">Browse the full course map →</a>
          </div>
        </div>
        <div className="fin-cert">
          <span className="fin-seal"><svg width="54" height="54" viewBox="0 0 54 54" aria-hidden="true"><circle cx="27" cy="27" r="22" fill="none" stroke="var(--current)" strokeWidth="2" /><circle cx="27" cy="27" r="16" fill="none" stroke="var(--current)" strokeWidth="1" strokeDasharray="3 3" /><path d="M20 27 l5 5 l9 -10" fill="none" stroke="var(--current)" strokeWidth="2.5" strokeLinecap="round" /></svg></span>
          <div className="eyebrow">certificate · level 2</div>
          <h4>Fathohm Engineer</h4>
          <p>Awarded for the design, spec, and hand-wired build of a working signal
            beacon. Timing chosen, resistors sized, circuit debugged by the bearer.</p>
          <p className="fin-no">NO. 0001 · FATHOHM.COM</p>
        </div>
      </div>
    </section>
  );
}

Object.assign(window, { HomeLoopHero, ShelfBand, FinaleBand, HG_ICONS });
