// v5 — Engagements section + Escher mark + site footer.
// Shared by the homepage (/) and the standalone contact page (/contact),
// so it lives outside v5-app.jsx (which owns the homepage mount).

// ENGAGEMENT MODES — content-driven cards for the contact section
// ENGAGEMENT MODES — ordered by how long they run, shortest first
const MODES = [
{
  name: "Workshop",
  range: "1\u20135 days \u00b7 with Portal",
  body: "A room with a deadline on it, and a decision before anyone leaves. I run these with Portal.",
  fit: "Best when the team has the ingredients and cannot agree on what to do with them.",
  href: "mailto:znerold@gmail.com?subject=Workshop%20with%20Portal",
  cursor: "1\u20135 days \u00b7 with Portal",
  // Idea commercialization timeline coverage — indices into IDEA_STAGES
  zones: [0, 1]
},
{
  name: "Prototype sprint",
  range: "1\u20133 weeks \u00b7 with Portal",
  body: "You end up with an artifact you can put in front of someone. It is built to be argued with.",
  fit: "Best when the decision is hard and the prototype has to do the convincing.",
  href: "mailto:znerold@gmail.com?subject=Prototype%20sprint%20with%20Portal",
  cursor: "1\u20133 wks \u00b7 research-fed",
  zones: [2, 3, 4]
},
{
  name: "Consulting",
  range: "4\u201312 weeks",
  body: "A named problem with a written scope, and an end date on the calendar. I do the work myself.",
  fit: "Best when there is a specific problem and a date it has to be solved by.",
  href: "mailto:znerold@gmail.com?subject=Consulting%20engagement",
  cursor: "4\u201312 wks \u00b7 scope-defined",
  zones: [1, 2, 3, 4]
},
{
  name: "Embedded advisory",
  range: "3\u20136 months",
  body: "I join the meetings you already have rather than adding new ones. Part time, for a few months.",
  fit: "Best when the decisions keep arriving and nobody in the room has done this before.",
  href: "mailto:znerold@gmail.com?subject=Embedded%20advisory",
  cursor: "3\u20136 mo \u00b7 in the room",
  zones: [0, 1, 2, 3, 4, 5, 6]
},
{
  name: "Selective staff leadership",
  range: "Open-ended",
  body: "Director or VP roles, in house, on payroll. I am open to it when the mandate is real and the people are ones I want to spend my Mondays with.",
  fit: "Best when the mandate is broad enough that nobody has written the job description yet.",
  href: "mailto:znerold@gmail.com?subject=Staff%20leadership%20conversation",
  cursor: "Full time \u00b7 in house",
  zones: [0, 1, 2, 3, 4, 5, 6]
}];


// Idea commercialization timeline — stages a new idea travels through
const IDEA_STAGES = [
{ id: "signal", label: "Signal", note: "Audience and category" },
{ id: "frame", label: "Frame", note: "Thesis and language" },
{ id: "concept", label: "Concept", note: "Directions with range" },
{ id: "validate", label: "Validate", note: "Cut down to one" },
{ id: "prototype", label: "Prototype", note: "Make it real" },
{ id: "ship", label: "Ship", note: "Production and handoff" },
{ id: "scale", label: "Scale", note: "Operate and learn" }];


const V5Engagements = () => {
  const [active, setActive] = useState(2); // start on Consulting
  const [paused, setPaused] = useState(false);

  useEffect(() => {
    if (paused) return;
    const id = setInterval(() => setActive((a) => (a + 1) % MODES.length), 5500);
    return () => clearInterval(id);
  }, [paused]);

  const pick = (i) => {setPaused(true);setActive(i);};
  const activeMode = MODES[active];
  const minZone = Math.min(...activeMode.zones);
  const maxZone = Math.max(...activeMode.zones);
  const N = IDEA_STAGES.length;

  return (
    <section id="engagements" className="v5-engagements" data-screen-label="Engagements">
      <div className="v4-container">
        {/* Compact opener — headline, then the one line that explains the timeline */}
        <header className="v5-engagements-head">
          <h2 className="v5-engagements-title" data-cursor="Where the work plugs in">
            <WordReveal text="How we can work together." stagger={55} />
          </h2>
        </header>

        {/* Idea-commercialization timeline — horizontal, shows active mode's coverage */}
        <div className="v5-engagements-timeline">
          <div className="v5-engagements-timeline-rail">
            {/* Background line */}
            <span className="v5-engagements-timeline-line"></span>

            {/* Active coverage band */}
            <span
              className="v5-engagements-timeline-band"
              style={{
                left: `${minZone / (N - 1) * 100}%`,
                right: `${100 - maxZone / (N - 1) * 100}%`
              }}
              aria-hidden="true">
            </span>

            {/* Stage markers */}
            {IDEA_STAGES.map((s, i) => {
              const isActive = activeMode.zones.includes(i);
              return (
                <div key={s.id}
                className={`v5-engagements-timeline-stage ${isActive ? "is-active" : ""}`}
                style={{ left: `${i / (N - 1) * 100}%` }}
                data-cursor={`Stage · ${s.label}`}>
                  
                  <span className="v5-engagements-timeline-dot"></span>
                  <span className="v5-engagements-timeline-stage-label">{s.label}</span>
                  <span className="v5-engagements-timeline-stage-note">{s.note}</span>
                </div>);

            })}
          </div>
        </div>

        {/* Two-column body — mode picker on left, dynamic detail on right */}
        <div className="v5-engagements-body">
          {/* Mode picker — linear list of selectable engagements */}
          <div className="v5-engagements-picker">
            {MODES.map((m, i) =>
            <button
              key={m.name}
              type="button"
              onClick={() => pick(i)}
              onMouseEnter={() => pick(i)}
              className={`v5-engagements-mode-row ${i === active ? "is-active" : ""}`}
              data-cursor={m.cursor}>
              
                <span className="v5-engagements-mode-row-name">{m.name}</span>
                <span className="v5-engagements-mode-row-range">{m.range}</span>
                <span className="v5-engagements-mode-row-marker" aria-hidden="true"></span>
              </button>
            )}
          </div>

          {/* Dynamic detail panel — transitions when active mode changes */}
          <div key={activeMode.name} className="v5-engagements-detail">
            <div className="v5-engagements-detail-head">
              <span className="v5-engagements-detail-meta">{activeMode.range}</span>

            </div>
            <div className="v5-engagements-detail-body">
              <h3 className="v5-engagements-detail-name">{activeMode.name}</h3>
              <p className="v5-engagements-detail-body-copy">{activeMode.body}</p>
              <Magnetic strength={14}>
                <a href={activeMode.href} className="v5-engagements-detail-cta" data-cursor={activeMode.cursor}>
                  <span>Talk about {/^(a|e|i|o|u)/i.test(activeMode.name) ? "an" : "a"} {activeMode.name.toLowerCase()}</span>
                  <span className="v5-engagements-detail-cta-arr">→</span>
                </a>
              </Magnetic>
            </div>
          </div>
        </div>
      </div>
    </section>);

};

// ESCHER MARK — three interlocked Borromean rings. Each pair overlaps with an
// alternating over/under weave (A>B, B>C, C>A) so no ring sits consistently in front;
// the eye keeps trying to resolve the stacking order. Minimal at rest, hover starts a
// slow rotation and a soft diffused halo, click twirls 540° flipping the weave parity.
const EscherMark = () => {
  const [twirl, setTwirl] = React.useState(0);
  return (
    <button
      type="button"
      className="cz-mark"
      onClick={() => setTwirl((t) => t + 1)}
      aria-label="Three interlocked rings. Click to bend them."
      data-cursor="Click to bend reality">
      
      <span className="cz-mark-twirl" style={{ transform: `rotate(${twirl * 540}deg)` }}>
        <svg className="cz-mark-svg" viewBox="0 0 40 40" aria-hidden="true">
          {/* Crossing chips (bg-colored) + clipped re-draws are how the weave is forged.
               Geometry: equilateral arrangement, centers at
               A(20,16) — top,  B(16.10, 22.75) — bottom-left,  C(23.90, 22.75) — bottom-right
               radius 7. Crossings calculated and chips centered on each. */}
          <defs>
            <clipPath id="czr-ab1"><rect x="21.59" y="20.78" width="3" height="3" /></clipPath>
            <clipPath id="czr-ab2"><rect x="11.51" y="14.97" width="3" height="3" /></clipPath>
            <clipPath id="czr-bc1"><rect x="18.5" y="27.06" width="3" height="3" /></clipPath>
            <clipPath id="czr-bc2"><rect x="18.5" y="15.44" width="3" height="3" /></clipPath>
          </defs>
          {/* Base rings — default stacking: C on top, then B, then A on bottom */}
          <circle cx="20" cy="16" r="7" className="cz-ring cz-ring-a" />
          <circle cx="16.10" cy="22.75" r="7" className="cz-ring cz-ring-b" />
          <circle cx="23.90" cy="22.75" r="7" className="cz-ring cz-ring-c" />
          {/* Make A win over B at both A-B crossings (flips B's default dominance) */}
          <rect x="21.59" y="20.78" width="3" height="3" className="cz-chip" />
          <g clipPath="url(#czr-ab1)"><circle cx="20" cy="16" r="7" className="cz-ring cz-ring-a" /></g>
          <rect x="11.51" y="14.97" width="3" height="3" className="cz-chip" />
          <g clipPath="url(#czr-ab2)"><circle cx="20" cy="16" r="7" className="cz-ring cz-ring-a" /></g>
          {/* Make B win over C at both B-C crossings */}
          <rect x="18.5" y="27.06" width="3" height="3" className="cz-chip" />
          <g clipPath="url(#czr-bc1)"><circle cx="16.10" cy="22.75" r="7" className="cz-ring cz-ring-b" /></g>
          <rect x="18.5" y="15.44" width="3" height="3" className="cz-chip" />
          <g clipPath="url(#czr-bc2)"><circle cx="16.10" cy="22.75" r="7" className="cz-ring cz-ring-b" /></g>
        </svg>
      </span>
    </button>);

};

// SUBSTANTIAL FOOTER — colophon-style closing surface
const V5Footer = () => {
  return (
    <footer className="v5-footer">
      <div className="v4-container">
        <div className="v5-footer-grid">
          {/* Identity column */}
          <div className="v5-footer-col v5-footer-col-id">
            <div className="v5-footer-mark" data-cursor="Chris Znerold · Boulder">
              <span className="v5-footer-mark-name" style={{ fontWeight: "600" }}>Chris Znerold</span>
            </div>
            <div className="v5-footer-pins">
              <a className="v5-footer-pin" href="https://portaldesign.com/" target="_blank" rel="noopener" data-cursor="Portal · studio" data-cursor-style="cta">
                <span className="v5-footer-pin-label">Studio</span>
                <span className="v5-footer-pin-val">Portal · est. 2013</span>
              </a>
              <a className="v5-footer-pin" href="https://www.colorado.edu/thebrandstudios/thefaculty" target="_blank" rel="noopener" data-cursor="CU Boulder · The Brand Studios" data-cursor-style="cta">
                <span className="v5-footer-pin-label">Faculty</span>
                <span className="v5-footer-pin-val">CU Boulder · 2017–now</span>
              </a>
              <a className="v5-footer-pin" href="https://www.dropbox.com/scl/fi/xtj1zu6pg8xi9m9ta3yf8/The-Bill-Bowen-House-Sunshine-Canyon-Colorado.pdf?rlkey=6v7zjmwu825a84pr4q1gmqg6o&st=2yaenyb8&dl=0" target="_blank" rel="noopener" data-cursor="The Bill Bowen House · Sunshine Canyon" data-cursor-style="cta">
                <span className="v5-footer-pin-label">Location</span>
                <span className="v5-footer-pin-val">Boulder, Colorado</span>
              </a>
              <a className="v5-footer-pin" href="/contact#engagements" data-cursor="The ways in" data-cursor-style="cta">
                <span className="v5-footer-pin-label">Engage</span>
                <span className="v5-footer-pin-val">Consulting · Advisory · Teaching · Leadership</span>
              </a>
            </div>
          </div>

          {/* Showcase column — single featured project, by artifact */}
          <div className="v5-footer-col v5-footer-col-showcase">
            <span className="v5-footer-col-label">In focus</span>
            <a href="/outdoorsy" className="v5-footer-feature" data-cursor="Open the full Outdoorsy case study" data-cursor-style="cta">
              <span className="v5-footer-feature-meta">
                <span className="v5-footer-feature-year">2022–24</span>
              </span>
              <span className="v5-footer-feature-name">Outdoorsy</span>
              <span className="v5-footer-feature-note">Host brand and a token-driven system across web and apps</span>
              <span className="v5-footer-feature-cta">
                <span>Open case study</span>
                <span className="v5-footer-feature-arr">→</span>
              </span>
            </a>
          </div>

          {/* Contact column */}
          <div className="v5-footer-col v5-footer-col-contact">
            <span className="v5-footer-col-label">Contact</span>
            <ul className="v5-footer-contact-list">
              <li>
                <span className="v5-footer-contact-key">Email</span>
                <Magnetic strength={8}>
                  <a href="mailto:znerold@gmail.com" data-cursor="Open in your mail client" className="v5-footer-contact-val">znerold@gmail.com</a>
                </Magnetic>
              </li>
              <li>
                <span className="v5-footer-contact-key">LinkedIn</span>
                <Magnetic strength={8}>
                  <a href="https://www.linkedin.com/in/znerold" target="_blank" rel="noopener" data-cursor="Open profile" className="v5-footer-contact-val">in/znerold</a>
                </Magnetic>
              </li>
            </ul>
            <Magnetic strength={10}>
              <a
                href="/contact#engagements"
                onClick={(e) => {
                  const el = document.getElementById("engagements");
                  if (!el) return;
                  e.preventDefault();
                  window.scrollTo({ top: el.offsetTop - 60, behavior: "smooth" });
                }}
                className="v5-footer-cta" data-cursor="2026 · taking introductions">
                <span className="v5-footer-cta-dot"></span>
                Available · 2026
                <span className="v5-footer-cta-arr">→</span>
              </a>
            </Magnetic>
          </div>
        </div>
      </div>
    </footer>);

};

// FOOT FIELD (pattern audit 19) — a slim band directly above the footer where the
// ASCII field resolves AVAILABLE: the masthead's device, bookending the page. Low
// opacity, and pointer-reactive only: the engine's `still` option paints once, plays
// the word in when the band comes into view, and otherwise moves only under the
// pointer. Mounted on / and /about (never /contact, never the 404, which keeps its
// own full-viewport field). The static pages get the same band from the footer
// snapshot (_tools/shell-footer). Nothing renders under 1024.
const V5_FOOT_FIELD_WORD = "AVAILABLE";
const V5FootField = () => {
  const Field = typeof window.V5AsciiField === "function" ? window.V5AsciiField : null;
  return (
    <div className="zn-foot-field zn-ascii-host" aria-hidden="true" data-zn-foot-field="">
      {Field ? React.createElement(Field, { name: "footer", word: V5_FOOT_FIELD_WORD, cycleMs: 4200, anchor: "center", opacity: 0.4, host: ".zn-foot-field", still: true }) : null}
    </div>);

};

// COLOPHON (pattern audit 16) — the four-pair meta grid that closes /about: what the
// site is set in, built on, drawn with, and when. One grid, four pairs, no sentences
// under a value. Said plainly: the "AI design engineering" claim wants the evidence.
const V5_COLOPHON = [
{ k: "Type", v: "Area Inktrap · Adobe Fonts" },
{ k: "Stack", v: "Static HTML · React · Vercel" },
{ k: "Engine", v: "ASCII field and motion layer · hand-built" },
{ k: "Built", v: "2026 · with Claude Code" }];

const V5Colophon = () => {
  return (
    <section className="v5-colophon" aria-label="Colophon" data-screen-label="Colophon">
      <div className="v4-container">
        <dl className="v5-colophon-grid" data-zn-fx="rise">
          {V5_COLOPHON.map((p) =>
          <div key={p.k} className="v5-colophon-pair">
              <dt className="v5-colophon-key">{p.k}</dt>
              <dd className="v5-colophon-val">{p.v}</dd>
            </div>
          )}
        </dl>
      </div>
    </section>);

};

Object.assign(window, { V5Engagements, EscherMark, V5Footer, V5FootField, V5Colophon, MODES, IDEA_STAGES, V5_COLOPHON, V5_FOOT_FIELD_WORD });
