// v5 — AI Design Fluency (split layout: Range vs Judgment)
// Two halves, each with a phrase as the header and a bullet list.

const AI_HELPS = [
"Gather and synthesize research signals",
"Generate broader creative range",
"Prototype visual and interface systems faster",
"Simulate users, edge cases, scenarios, objections",
"Pressure-test language and positioning",
"Scaffold code, components, and interaction models",
"Build bespoke visual systems",
"Draft strategy, decks, and prototypes",
"Translate concepts into production-ready systems with human review"];


const AI_NOTS = [
"Replace taste.",
"Replace judgment.",
"Understand context by default.",
"Absolve the designer from responsibility.",
"Decide what should be real."
// intentionally one fewer than AI_HELPS — the constraints are tighter
];

// Range marker — dots scattering outward as section enters viewport
const RangeMarker = () => {
  const ref = useRef(null);
  const [seen, setSeen] = useState(false);
  useEffect(() => {
    const el = ref.current;if (!el) return;
    const io = new IntersectionObserver(([e]) => {
      if (e.isIntersecting) {setSeen(true);io.disconnect();}
    }, { threshold: 0.2 });
    io.observe(el);
    return () => io.disconnect();
  }, []);
  const dots = Array.from({ length: 28 }).map((_, i) => {
    const angle = -100 + i / 27 * 200;
    const r = 60 + i * 37 % 90;
    const x = Math.cos(angle * Math.PI / 180) * r;
    const y = Math.sin(angle * Math.PI / 180) * r;
    return { x, y, d: i * 35 };
  });
  return (
    <svg ref={ref} className={`v5-ai-marker v5-ai-marker-range ${seen ? "is-in" : ""}`} viewBox="-160 -110 320 220" aria-hidden="true">
      <circle cx="-130" cy="0" r="4" fill="#D86A48" />
      <circle cx="-130" cy="0" r="8" fill="none" stroke="#D86A48" strokeWidth="0.6" opacity="0.5" />
      <text x="-130" y="22" textAnchor="middle" fontFamily="JetBrains Mono, monospace" fontSize="9" letterSpacing="2" fill="rgba(242,238,230,0.55)">PROMPT</text>
      {dots.map((d, i) =>
      <g key={i}>
          <line x1="-130" y1="0" x2={d.x} y2={d.y}
        stroke="#D86A48" strokeWidth="0.5" opacity="0.35"
        className="v5-ai-marker-line"
        style={{ "--d": `${d.d}ms` }} />
        
          <circle cx={d.x} cy={d.y} r="2.4"
        fill="#D86A48"
        opacity={0.6 + i % 5 * 0.08}
        className="v5-ai-marker-dot"
        style={{ "--d": `${d.d + 150}ms` }} />
        
        </g>
      )}
    </svg>);

};

// Judgment marker — many dots condensing inward toward one accent point
const JudgmentMarker = () => {
  const ref = useRef(null);
  const [seen, setSeen] = useState(false);
  useEffect(() => {
    const el = ref.current;if (!el) return;
    const io = new IntersectionObserver(([e]) => {
      if (e.isIntersecting) {setSeen(true);io.disconnect();}
    }, { threshold: 0.2 });
    io.observe(el);
    return () => io.disconnect();
  }, []);
  const dots = Array.from({ length: 22 }).map((_, i) => {
    const angle = -180 + i / 21 * 360;
    const r = 70 + i * 31 % 50;
    const x = Math.cos(angle * Math.PI / 180) * r;
    const y = Math.sin(angle * Math.PI / 180) * r;
    return { x, y, d: i * 42 };
  });
  return (
    <svg ref={ref} className={`v5-ai-marker v5-ai-marker-judgment ${seen ? "is-in" : ""}`} viewBox="-160 -110 320 220" aria-hidden="true">
      {dots.map((d, i) =>
      <g key={i}>
          <line x1={d.x} y1={d.y} x2="0" y2="0"
        stroke="rgba(242,238,230,0.45)" strokeWidth="0.5" opacity="0.4"
        className="v5-ai-marker-line"
        style={{ "--d": `${d.d}ms` }} />
        
          <circle cx={d.x} cy={d.y} r="2"
        fill="rgba(242,238,230,0.6)" opacity="0.65"
        className="v5-ai-marker-dot v5-ai-marker-dot-shrink"
        style={{ "--d": `${d.d + 100}ms` }} />
        
        </g>
      )}
      <circle cx="0" cy="0" r="10" fill="#D86A48" className="v5-ai-marker-core" style={{ "--d": `${22 * 42 + 200}ms` }} />
      <circle cx="0" cy="0" r="16" fill="none" stroke="#D86A48" strokeWidth="1" opacity="0.7" className="v5-ai-marker-core-halo" style={{ "--d": `${22 * 42 + 300}ms` }} />
      <text x="0" y="38" textAnchor="middle" fontFamily="JetBrains Mono, monospace" fontSize="9" letterSpacing="2" fill="rgba(242,238,230,0.6)">DECIDE</text>
    </svg>);

};

const V5AIFluency = () => {
  return (
    <section className="v5-ai" data-screen-label="AI Design Fluency">
      <div className="v4-container">
        <header className="v5-ai-head v5-ai-head-2col">
          <div className="v5-ai-head-left">
            <span className="v5-ai-eyebrow">
              <span className="v5-ai-eyebrow-rule"></span>
              <span className="v5-ai-eyebrow-num">02C</span>
              <span>AI design fluency · the new instrument</span>
            </span>
            <h2 className="v5-ai-title" data-cursor="The new instrument">
              <WordReveal text="AI is now part of" stagger={60} />
              {" "}
              <span className="emph"><WordReveal text="the design instrument." stagger={70} startDelay={300} /></span>
            </h2>
          </div>
          <p className="v5-ai-lede">
            <FadeIn delay={250}>
              Not a gimmick. Not a separate tool track. AI is now part of how the practice researches, explores, prototypes, critiques, writes, designs, and builds. The value is not that AI makes things. The value is knowing what to ask for, what to reject, what to refine, and what should exist at all.
            </FadeIn>
          </p>
        </header>

        {/* SPLIT — RANGE vs JUDGMENT */}
        <div className="v5-ai-split">
          {/* LEFT — Range */}
          <div className="v5-ai-half v5-ai-half-range">
            <div className="v5-ai-half-marker"><RangeMarker /></div>
            <span className="v5-ai-half-eyebrow">— Side A · the expansion</span>
            <h3 className="v5-ai-half-title">
              <SplitText text="AI expands the field." className="v5-ai-half-title-split" />
            </h3>
            <p className="v5-ai-half-sub"><span className="emph">The practice creates meaning.</span></p>
            <span className="v5-ai-half-list-label">— AI helps me ({String(AI_HELPS.length).padStart(2, "0")})</span>
            <ul className="v5-ai-half-list">
              {AI_HELPS.map((h, i) =>
              <FadeIn as="li" key={h} delay={i * 70} className="v5-ai-half-item" data-cursor={`Range / ${String(i + 1).padStart(2, "0")}`}>
                  <span className="v5-ai-half-item-n">{String(i + 1).padStart(2, "0")}</span>
                  <span className="v5-ai-half-item-rule"></span>
                  <span className="v5-ai-half-item-text">{h}</span>
                </FadeIn>
              )}
            </ul>
          </div>

          {/* Center divider with bridge glyph */}
          <div className="v5-ai-divider" aria-hidden="true">
            <svg viewBox="0 0 24 240" className="v5-ai-divider-svg">
              <line x1="12" y1="0" x2="12" y2="240" stroke="var(--v4-line)" strokeDasharray="2 6" />
              <circle cx="12" cy="120" r="6" fill="var(--v4-paper)" stroke="var(--v4-accent)" strokeWidth="1" />
              <text x="12" y="123" textAnchor="middle" fontFamily="var(--mono)" fontSize="10" fill="var(--v4-accent)">×</text>
            </svg>
          </div>

          {/* RIGHT — Judgment */}
          <div className="v5-ai-half v5-ai-half-judgment">
            <div className="v5-ai-half-marker"><JudgmentMarker /></div>
            <span className="v5-ai-half-eyebrow">— Side B · the constraint</span>
            <h3 className="v5-ai-half-title">
              <SplitText text="Judgment narrows the field." className="v5-ai-half-title-split" />
            </h3>
            <p className="v5-ai-half-sub"><span className="emph">The work is deciding what deserves to exist.</span></p>
            <span className="v5-ai-half-list-label">— AI does not ({String(AI_NOTS.length).padStart(2, "0")})</span>
            <ul className="v5-ai-half-list v5-ai-half-list-nots">
              {AI_NOTS.map((h, i) =>
              <FadeIn as="li" key={h} delay={i * 90} className="v5-ai-half-item" data-cursor={`Limit / ${String(i + 1).padStart(2, "0")}`}>
                  <span className="v5-ai-half-item-n">{String(i + 1).padStart(2, "0")}</span>
                  <span className="v5-ai-half-item-rule"></span>
                  <span className="v5-ai-half-item-text">{h}</span>
                </FadeIn>
              )}
            </ul>
          </div>
        </div>

        <p className="v5-ai-foot" style={{ display: "none" }}></p>
      </div>
    </section>);

};

Object.assign(window, { V5AIFluency, RangeMarker, JudgmentMarker });