/* global React */
// Hero — Ajaia AI Training for Enterprises
//  · LEFT: copy + CTAs + enhanced stats strip
//  · RIGHT: central glowing network orb + small light-glass widgets
//  · Motion: orb breathes, edges & travelling packets pulse, widgets float gently.
//    No mouse parallax on widgets (user request).

const { useState: useStateH, useEffect: useEffectH, useRef: useRefH } = React;

// ────────────────────────────────────────────────────────────────────
// Hook: dampened mouse parallax (used by the orb only)
// ────────────────────────────────────────────────────────────────────
function useParallax() {
  const [target, setTarget] = useStateH({ x: 0, y: 0 });
  const [value, setValue] = useStateH({ x: 0, y: 0 });
  const reduced = useRefH(false);

  useEffectH(() => {
    reduced.current = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
    if (reduced.current) return;
    const onMove = (e) => {
      const w = window.innerWidth,h = window.innerHeight;
      setTarget({
        x: (e.clientX / w - 0.5) * 2,
        y: (e.clientY / h - 0.5) * 2
      });
    };
    window.addEventListener("mousemove", onMove, { passive: true });
    return () => window.removeEventListener("mousemove", onMove);
  }, []);

  useEffectH(() => {
    if (reduced.current) return;
    let raf;
    const loop = () => {
      setValue((v) => ({
        x: v.x + (target.x - v.x) * 0.08,
        y: v.y + (target.y - v.y) * 0.08
      }));
      raf = requestAnimationFrame(loop);
    };
    raf = requestAnimationFrame(loop);
    return () => cancelAnimationFrame(raf);
  }, [target]);

  return value;
}

// ────────────────────────────────────────────────────────────────────
// Hook: count-up animation when element enters view
// ────────────────────────────────────────────────────────────────────
function useCountTo(target, duration = 1600) {
  const ref = useRefH(null);
  const [val, setVal] = useStateH(0);
  useEffectH(() => {
    let raf,startedAt = 0,started = false;
    const io = new IntersectionObserver(([entry]) => {
      if (entry.isIntersecting && !started) {
        started = true;
        const step = (t) => {
          if (!startedAt) startedAt = t;
          const p = Math.min(1, (t - startedAt) / duration);
          const eased = 1 - Math.pow(1 - p, 3);
          setVal(target * eased);
          if (p < 1) raf = requestAnimationFrame(step);
        };
        raf = requestAnimationFrame(step);
      }
    }, { threshold: 0.4 });
    if (ref.current) io.observe(ref.current);
    return () => {io.disconnect();cancelAnimationFrame(raf);};
  }, [target, duration]);
  return [ref, val];
}

// ────────────────────────────────────────────────────────────────────
// Central network-graph orb
// ────────────────────────────────────────────────────────────────────
function NetworkOrb({ parallax }) {
  const nodes = [
  { x: 130, y: 170, r: 8, active: false, delay: 0 },
  { x: 130, y: 215, r: 8, active: false, delay: 0.3 },
  { x: 130, y: 260, r: 8, active: false, delay: 0.6 },
  { x: 175, y: 192, r: 8, active: false, delay: 0.9 },
  { x: 175, y: 238, r: 8, active: false, delay: 1.2 },
  { x: 230, y: 192, r: 16, active: true, delay: 0 },
  { x: 230, y: 238, r: 16, active: true, delay: 0.6 },
  { x: 285, y: 215, r: 10, active: true, delay: 1.0 },
  { x: 290, y: 170, r: 7, active: false, delay: 1.5 },
  { x: 290, y: 260, r: 7, active: false, delay: 1.8 }];

  const edges = [
  [0, 5], [1, 5], [2, 6], [3, 5], [3, 6], [4, 6],
  [5, 7], [6, 7], [5, 8], [6, 9], [7, 8], [7, 9]];


  const ox = parallax.x * 6;
  const oy = parallax.y * 6;

  return (
    <div
      className="orb-wrap"
      style={{
        position: "absolute",
        inset: 0,
        display: "grid",
        placeItems: "center",
        transform: `translate3d(${ox}px, ${oy}px, 0)`,
        transition: "transform 600ms cubic-bezier(0.2, 0.9, 0.2, 1)"
      }}>
      <div style={{ position: "relative", width: 480, height: 480, display: "grid", placeItems: "center" }}>
        <div className="orb-halo" />
        <div className="orb-frame">
          <svg viewBox="0 0 400 400" width="100%" height="100%" style={{ position: "absolute", inset: 0 }}>
            <defs>
              <radialGradient id="ringFade" cx="50%" cy="50%" r="50%">
                <stop offset="0%" stopColor="rgba(151,194,247,0.0)" />
                <stop offset="60%" stopColor="rgba(151,194,247,0.20)" />
                <stop offset="100%" stopColor="rgba(151,194,247,0.0)" />
              </radialGradient>
              <radialGradient id="centerGlow" cx="50%" cy="50%" r="50%">
                <stop offset="0%" stopColor="rgba(94,142,255,0.65)" />
                <stop offset="55%" stopColor="rgba(42,76,255,0.12)" />
                <stop offset="100%" stopColor="rgba(42,76,255,0.0)" />
              </radialGradient>
              <linearGradient id="edgeGrad" x1="0%" y1="50%" x2="100%" y2="50%">
                <stop offset="0%" stopColor="rgba(151,194,247,0.45)" />
                <stop offset="50%" stopColor="rgba(151,194,247,0.85)" />
                <stop offset="100%" stopColor="rgba(151,194,247,0.45)" />
              </linearGradient>
              <radialGradient id="nodeActive" cx="40%" cy="40%" r="70%">
                <stop offset="0%" stopColor="#A8C7FF" />
                <stop offset="55%" stopColor="#3B6DF5" />
                <stop offset="100%" stopColor="#2A4CFF" />
              </radialGradient>
              <filter id="softGlow" x="-50%" y="-50%" width="200%" height="200%">
                <feGaussianBlur stdDeviation="3" result="b" />
                <feMerge>
                  <feMergeNode in="b" />
                  <feMergeNode in="SourceGraphic" />
                </feMerge>
              </filter>
            </defs>

            <circle cx="200" cy="215" r="170" fill="url(#centerGlow)" className="breathe-glow" />

            <g className="ring-rotate">
              <circle cx="200" cy="215" r="155" fill="none" stroke="url(#ringFade)" strokeWidth="1" />
              <circle cx="200" cy="215" r="120" fill="none" stroke="rgba(151,194,247,0.18)" strokeWidth="1" strokeDasharray="2 6" />
              <circle cx="200" cy="215" r="85" fill="none" stroke="rgba(151,194,247,0.22)" strokeWidth="1" />
            </g>

            <g>
              {edges.map(([a, b], i) =>
              <line
                key={i}
                x1={nodes[a].x} y1={nodes[a].y}
                x2={nodes[b].x} y2={nodes[b].y}
                stroke="url(#edgeGrad)"
                strokeWidth="1.2"
                strokeLinecap="round"
                opacity="0.55"
                className="edge-fade"
                style={{ animationDelay: `${(i * 0.18).toFixed(2)}s` }} />

              )}
            </g>

            {/* Traveling glow packets along edges */}
            <g style={{ pointerEvents: "none" }}>
              {edges.map(([a, b], i) => {
                const nA = nodes[a],nB = nodes[b];
                const delay = i * 0.45 % 3.6;
                const dur = 2.4 + i % 3 * 0.4;
                return (
                  <g key={`pkt-${i}`}>
                    <circle r="4.5" fill="rgba(151,194,247,0.25)" filter="url(#softGlow)">
                      <animateMotion
                        dur={`${dur}s`}
                        begin={`${delay.toFixed(2)}s`}
                        repeatCount="indefinite"
                        keyTimes="0;1"
                        keySplines="0.4 0 0.2 1"
                        calcMode="spline"
                        path={`M${nA.x},${nA.y} L${nB.x},${nB.y}`} />
                      <animate attributeName="opacity"
                      values="0;1;1;0" keyTimes="0;0.15;0.85;1"
                      dur={`${dur}s`} begin={`${delay.toFixed(2)}s`}
                      repeatCount="indefinite" />
                    </circle>
                    <circle r="2.2" fill="#DCE9FF">
                      <animateMotion
                        dur={`${dur}s`}
                        begin={`${delay.toFixed(2)}s`}
                        repeatCount="indefinite"
                        keyTimes="0;1"
                        keySplines="0.4 0 0.2 1"
                        calcMode="spline"
                        path={`M${nA.x},${nA.y} L${nB.x},${nB.y}`} />
                      <animate attributeName="opacity"
                      values="0;1;1;0" keyTimes="0;0.15;0.85;1"
                      dur={`${dur}s`} begin={`${delay.toFixed(2)}s`}
                      repeatCount="indefinite" />
                    </circle>
                  </g>);

              })}
            </g>

            <g filter="url(#softGlow)">
              {nodes.map((n, i) =>
              <g key={i} className="node-pop" style={{ animationDelay: `${0.4 + n.delay * 0.3}s` }}>
                  {n.active ?
                <>
                      <circle cx={n.x} cy={n.y} r={n.r + 8} fill="rgba(59,109,245,0.18)" className="node-pulse" style={{ animationDelay: `${n.delay}s` }} />
                      <circle cx={n.x} cy={n.y} r={n.r} fill="url(#nodeActive)" />
                      <circle cx={n.x - n.r * 0.3} cy={n.y - n.r * 0.35} r={n.r * 0.32} fill="rgba(255,255,255,0.55)" />
                    </> :

                <circle cx={n.x} cy={n.y} r={n.r} fill="rgba(10,21,48,0.85)" stroke="rgba(151,194,247,0.55)" strokeWidth="1.4" />
                }
                </g>
              )}
            </g>
          </svg>

          {/* Decorative outline triangles */}
          <svg width="22" height="22" viewBox="0 0 22 22" style={{ position: "absolute", top: 28, right: 84, opacity: 0.35 }}>
            <path d="M11 3 L20 19 L2 19 Z" fill="none" stroke="rgba(151,194,247,0.7)" strokeWidth="1" />
          </svg>
          <svg width="22" height="22" viewBox="0 0 22 22" style={{ position: "absolute", top: 36, right: 28, opacity: 0.45 }}>
            <path d="M11 3 L20 19 L2 19 Z" fill="none" stroke="rgba(151,194,247,0.8)" strokeWidth="1" />
          </svg>
          <div style={{ position: "absolute", top: 100, right: 22, width: 12, height: 12, background: "#0a1340", border: "1px solid rgba(151,194,247,0.4)" }} />
          <div style={{ position: "absolute", bottom: 70, right: 88, width: 12, height: 12, background: "#0a1340", border: "1px solid rgba(151,194,247,0.3)" }} />
        </div>
      </div>
    </div>);

}

// ────────────────────────────────────────────────────────────────────
// Floating widget shell — light glassmorphic. NO mouse parallax.
// ────────────────────────────────────────────────────────────────────
function FloatWidget({ style, delay = 0, floatClass = "float-1", children }) {
  return (
    <div
      className={`widget-enter ${floatClass}`}
      style={{
        position: "absolute",
        background: "linear-gradient(180deg, rgba(255,255,255,0.18) 0%, rgba(255,255,255,0.07) 100%)",
        border: "1px solid rgba(255,255,255,0.30)",
        borderRadius: 14,
        backdropFilter: "blur(24px) saturate(160%)",
        WebkitBackdropFilter: "blur(24px) saturate(160%)",
        boxShadow:
        "0 22px 48px -18px rgba(0,12,55,0.55), 0 1px 0 0 rgba(255,255,255,0.30) inset, 0 0 0 1px rgba(151,194,247,0.06) inset",
        animationDelay: `${delay}ms`,
        color: "white",
        ...style
      }}>
      {children}
    </div>);

}

// ────────────────────────────────────────────────────────────────────
// Widget contents — smaller, light glass styles
// ────────────────────────────────────────────────────────────────────
function LiveWorkshopWidget() {
  const avatars = [
  { bg: "#3B6DF5", initial: "S" },
  { bg: "#5683FF", initial: "M" },
  { bg: "#1E3FCE", initial: "K" }];

  return (
    <div style={{ padding: "12px 14px", width: 196 }}>
      <div style={{
        fontFamily: "var(--font-sans)", fontWeight: 700, fontSize: 9.5,
        color: "rgba(255,255,255,0.78)", letterSpacing: "0.18em", textTransform: "uppercase"
      }}>Learners online</div>

      <div style={{ marginTop: 8, display: "flex", alignItems: "center", gap: 10 }}>
        <div style={{
          fontFamily: "var(--font-display)", fontWeight: 700,
          fontSize: 26, lineHeight: 1, letterSpacing: "-0.03em",
          color: "white"
        }} className="num-tabular">327</div>

        <div style={{ display: "flex", alignItems: "center" }}>
          {avatars.map((a, i) =>
          <div key={i} style={{
            width: 20, height: 20, borderRadius: "50%",
            background: a.bg,
            border: "1.5px solid rgba(255,255,255,0.92)",
            marginLeft: i === 0 ? 0 : -7,
            display: "grid", placeItems: "center",
            fontFamily: "var(--font-sans)", fontWeight: 600, fontSize: 9,
            color: "white", letterSpacing: "-0.02em",
            boxShadow: "0 3px 8px -2px rgba(0,0,0,0.35)"
          }}>{a.initial}</div>
          )}
          <div style={{
            marginLeft: -7, height: 20, padding: "0 6px", borderRadius: 10,
            background: "rgba(151,194,247,0.32)",
            border: "1.5px solid rgba(255,255,255,0.92)",
            display: "grid", placeItems: "center",
            fontFamily: "var(--font-sans)", fontWeight: 600, fontSize: 9,
            color: "white", letterSpacing: "-0.02em"
          }}>+12</div>
        </div>
      </div>

      <div style={{
        marginTop: 10,
        fontFamily: "var(--font-sans)", fontSize: 11.5, lineHeight: 1.4,
        color: "rgba(255,255,255,0.82)", letterSpacing: "-0.005em"
      }}>Live in <span style={{ color: "#DCE9FF", fontWeight: 600 }}>Claude for Ops</span></div>
    </div>);

}

function AdoptionWidget() {
  const bars = [9, 12, 10, 15, 19, 23, 28];
  return (
    <div style={{ padding: "12px 14px", width: 188 }}>
      <div style={{
        fontFamily: "var(--font-sans)", fontWeight: 700, fontSize: 9.5,
        color: "rgba(255,255,255,0.78)", letterSpacing: "0.18em", textTransform: "uppercase"
      }}>Weekly adoption</div>
      <div style={{ marginTop: 6, display: "flex", alignItems: "baseline", gap: 6 }}>
        <div style={{
          fontFamily: "var(--font-display)", fontWeight: 700,
          fontSize: 24, lineHeight: 1, letterSpacing: "-0.03em", color: "white"
        }} className="num-tabular">+38%</div>
        <div style={{
          fontFamily: "var(--font-sans)", fontSize: 10.5,
          color: "#DCE9FF", display: "flex", alignItems: "center", gap: 3
        }}>
          <svg width="9" height="9" viewBox="0 0 12 12" fill="none" stroke="currentColor" strokeWidth="1.8"><path d="M6 10V2M2 6l4-4 4 4" strokeLinecap="round" /></svg>
          vs. last
        </div>
      </div>
      <div style={{ marginTop: 10, display: "flex", alignItems: "flex-end", gap: 4, height: 26 }}>
        {bars.map((h, i) =>
        <div
          key={i}
          className="bar-rise"
          style={{
            width: 14, height: `${h}px`,
            background: i === bars.length - 1 ?
            "linear-gradient(180deg, #DCE9FF 0%, #5683FF 100%)" :
            "linear-gradient(180deg, rgba(220,233,255,0.85) 0%, rgba(86,131,255,0.65) 100%)",
            borderRadius: 2,
            boxShadow: i === bars.length - 1 ? "0 0 10px rgba(151,194,247,0.6)" : "none",
            animationDelay: `${300 + i * 70}ms`
          }} />

        )}
      </div>
    </div>);

}

function LiteracyScoreWidget() {
  return (
    <div style={{ padding: "12px 14px", width: 196 }}>
      <div style={{ display: "flex", alignItems: "center", gap: 9 }}>
        <div style={{
          width: 18, height: 18, borderRadius: 5,
          background: "linear-gradient(135deg, #5683FF 0%, #2A4CFF 100%)",
          display: "grid", placeItems: "center",
          boxShadow: "0 4px 10px -3px rgba(86,131,255,0.6)",
          flexShrink: 0
        }}>
          <svg width="10" height="10" viewBox="0 0 14 14" fill="none"
          stroke="white" strokeWidth="2.4" strokeLinecap="round" strokeLinejoin="round">
            <path d="M2.5 7l3 3 6-6.5" />
          </svg>
        </div>
        <div style={{ display: "flex", flexDirection: "column", gap: 1 }}>
          <div style={{
            fontFamily: "var(--font-sans)", fontWeight: 600, fontSize: 11.5,
            color: "white", letterSpacing: "-0.01em", lineHeight: 1.2
          }}>Module check</div>
          <div style={{
            fontFamily: "var(--font-mono)", fontSize: 9, color: "rgba(255,255,255,0.72)",
            letterSpacing: "0.06em"
          }}>TRACK-02</div>
        </div>
      </div>

      <div style={{ marginTop: 10, display: "flex", alignItems: "baseline", gap: 5 }}>
        <div style={{
          fontFamily: "var(--font-display)", fontWeight: 700,
          fontSize: 22, lineHeight: 1, letterSpacing: "-0.03em", color: "white"
        }} className="num-tabular">12</div>
        <div style={{
          fontFamily: "var(--font-display)", fontWeight: 500,
          fontSize: 14, lineHeight: 1, letterSpacing: "-0.02em",
          color: "rgba(255,255,255,0.60)"
        }} className="num-tabular">/ 12</div>
        <div style={{
          marginLeft: 4,
          fontFamily: "var(--font-sans)", fontWeight: 500, fontSize: 11,
          color: "rgba(255,255,255,0.85)", letterSpacing: "-0.005em"
        }}>cleared</div>
      </div>

      <div style={{
        marginTop: 10, height: 3, borderRadius: 999,
        background: "rgba(255,255,255,0.22)", overflow: "hidden"
      }}>
        <div className="grow-bar" style={{
          height: "100%", width: "100%",
          background: "linear-gradient(90deg, #5683FF 0%, #DCE9FF 100%)",
          boxShadow: "0 0 8px rgba(151,194,247,0.55)",
          animationDelay: "700ms"
        }} />
      </div>
    </div>);

}

function ModuleChipWidget() {
  return (
    <div style={{ padding: "7px 10px", display: "flex", alignItems: "center", gap: 7 }}>
      <div style={{
        width: 14, height: 14, borderRadius: 3,
        background: "rgba(127,240,190,0.28)",
        border: "1px solid rgba(127,240,190,0.65)",
        color: "#9CFFCB",
        display: "grid", placeItems: "center"
      }}>
        <svg width="8" height="8" viewBox="0 0 12 12" fill="none" stroke="currentColor" strokeWidth="2.4" strokeLinecap="round" strokeLinejoin="round">
          <path d="M2 6l3 3 5-6" />
        </svg>
      </div>
      <div style={{ fontFamily: "var(--font-mono)", fontSize: 9.5, color: "white", letterSpacing: "0.08em", textTransform: "uppercase" }}>Module 04 · Done</div>
    </div>);

}

// ────────────────────────────────────────────────────────────────────
// Enhanced stats strip — dividers, count-up, mini accents
// ────────────────────────────────────────────────────────────────────
function StatCell({ value, suffix, label, accent, isLast, stars = false }) {
  // value is the formatted final string (e.g. "25k", "4.8"); we drive count-up
  // by parsing the numeric portion and re-formatting per cell.
  const parsed = parseFloat(String(value).replace(/[^0-9.]/g, ""));
  const isFloat = String(value).includes(".");
  const isK = String(value).toLowerCase().includes("k");
  const [ref, current] = useCountTo(parsed, 1500);

  const display = isFloat ?
  current.toFixed(1) :
  isK ?
  Math.round(current) + "k" :
  Math.round(current).toString();

  return (
    <div ref={ref} style={{
      flex: 1, minWidth: 0,
      display: "flex", flexDirection: "column", gap: 8,
      paddingRight: isLast ? 0 : 24,
      borderRight: isLast ? "none" : "1px solid rgba(255,255,255,0.10)",
      position: "relative"
    }}>
      {/* Accent dot */}
      <div style={{ display: "flex", alignItems: "center", gap: 8 }}>
        <span style={{
          width: 6, height: 6, borderRadius: 999,
          background: accent,
          boxShadow: `0 0 10px ${accent}`
        }} />
        <div style={{
          fontFamily: "var(--font-mono)", fontSize: 10.5,
          color: "rgba(255,255,255,0.62)",
          letterSpacing: "0.14em", textTransform: "uppercase"
        }}>{label}</div>
      </div>

      {/* Number */}
      <div style={{
        display: "flex", alignItems: "baseline", gap: 2,
        fontFamily: "var(--font-display)", fontWeight: 700,
        fontSize: 30, lineHeight: 1, letterSpacing: "-0.03em",
        color: "white"
      }} className="num-tabular">
        {display}
        <span style={{
          fontSize: 22, color: "#DCE9FF", marginLeft: 1, letterSpacing: "-0.02em"
        }}>{suffix}</span>
      </div>

      {/* Mini sparkline OR star row */}
      {stars ?
      <StarRow value={parseFloat(String(display)) || 0} size={12} color={accent} /> :

      <svg width="64" height="10" viewBox="0 0 64 10" style={{ display: "block" }}>
          <polyline
          points="1,8 12,6 22,7 32,4 42,5 52,2 62,3"
          fill="none"
          stroke={accent}
          strokeWidth="1.2"
          strokeLinecap="round"
          strokeLinejoin="round"
          opacity="0.7" />
        </svg>
      }
    </div>);

}

// Star rating renderer — 5 stars filled to a target value (e.g. 4.8)
function StarRow({ value = 4.8, size = 13, color = "#FFC857" }) {
  const pct = Math.max(0, Math.min(1, value / 5));
  return (
    <div style={{ position: "relative", display: "inline-flex", gap: 2, lineHeight: 1 }}>
      {/* Base outline row */}
      <div style={{ display: "inline-flex", gap: 2 }}>
        {[0, 1, 2, 3, 4].map((i) =>
        <svg key={i} width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="rgba(255,255,255,0.30)" strokeWidth="1.4">
            <path d="M12 2l3.1 6.6 7.2 1-5.2 5 1.2 7.2L12 18.4 5.7 21.8l1.2-7.2L1.7 9.6l7.2-1L12 2z" />
          </svg>
        )}
      </div>
      {/* Filled row clipped to pct */}
      <div style={{
        position: "absolute", inset: 0, overflow: "hidden",
        width: `calc(${pct * 100}% + ${Math.floor(pct * 5) * 2}px)`,
        display: "inline-flex", gap: 2, pointerEvents: "none"
      }}>
        {[0, 1, 2, 3, 4].map((i) =>
        <svg key={i} width={size} height={size} viewBox="0 0 24 24" fill={color} style={{ flexShrink: 0 }}>
            <path d="M12 2l3.1 6.6 7.2 1-5.2 5 1.2 7.2L12 18.4 5.7 21.8l1.2-7.2L1.7 9.6l7.2-1L12 2z" />
          </svg>
        )}
      </div>
    </div>);

}

function StatsStrip() {
  const stats = [
  { value: "25k", suffix: "+", label: "Employees Trained", accent: "#97C2F8" },
  { value: "100", suffix: "+", label: "Enterprises Supported", accent: "#5683FF" },
  { value: "4.8", suffix: "", label: "Avg. Feedback", accent: "#FFC857", stars: true }];

  return (
    <div className="stats-strip" style={{
      marginTop: 32,
      padding: "20px 24px",
      background: "linear-gradient(180deg, rgba(255,255,255,0.06) 0%, rgba(255,255,255,0.02) 100%)",
      border: "1px solid rgba(255,255,255,0.10)",
      borderRadius: 12,
      backdropFilter: "blur(12px)",
      WebkitBackdropFilter: "blur(12px)",
      display: "flex", alignItems: "center", gap: 24,
      position: "relative", overflow: "hidden"
    }}>
      {/* Subtle inner accent strip */}
      <div style={{
        position: "absolute", top: 0, left: 0, right: 0, height: 1,
        background: "linear-gradient(90deg, transparent, rgba(151,194,247,0.40), transparent)"
      }} />
      {stats.map((s, i) =>
      <StatCell
        key={i}
        value={s.value}
        suffix={s.suffix}
        label={s.label}
        accent={s.accent}
        stars={s.stars}
        isLast={i === stats.length - 1} />

      )}
    </div>);

}

// ────────────────────────────────────────────────────────────────────
// HERO
// ────────────────────────────────────────────────────────────────────
function Hero() {
  return (
    <section style={{
      position: "relative",
      background: "radial-gradient(ellipse 90% 70% at 50% 0%, #0e1a4a 0%, #0a1340 45%, #07103a 100%)",
      paddingTop: 132, paddingBottom: 120,
      overflow: "hidden",
      color: "white"
    }}>
      <div className="hero-glow" />
      <div className="grid-bg" />
      <div className="noise" />

      <div style={{
        position: "absolute", top: 68, left: 0, right: 0, height: 1,
        background: "linear-gradient(90deg, transparent, rgba(151,194,247,0.20), transparent)"
      }} />

      <div className="container" style={{ position: "relative" }}>
        <div style={{ display: "grid", gridTemplateColumns: "1.05fr 1fr", gap: 64, alignItems: "center" }} className="hero-grid">

          {/* LEFT — Copy + CTAs + stats */}
          <div className="reveal">
            <Eyebrow tone="dark">AI training & workforce enablement</Eyebrow>

            <h1 className="hero-title" style={{
              marginTop: 24,
              fontFamily: "var(--font-display)", fontWeight: 700,
              fontSize: 64, lineHeight: 1.04, letterSpacing: "-0.03em",
              color: "white"
            }}>
              <span>AI Training for </span>
              <span style={{
                background: "linear-gradient(135deg, #97C2F8 0%, #B6D4FA 50%, #FFFFFF 100%)",
                WebkitBackgroundClip: "text", backgroundClip: "text",
                WebkitTextFillColor: "transparent", color: "transparent"
              }}>Enterprises</span>
            </h1>

            <p style={{
              marginTop: 24, maxWidth: 580,
              fontFamily: "var(--font-sans)", fontSize: 17.5, lineHeight: 1.6,
              color: "rgba(255,255,255,0.78)", letterSpacing: "-0.005em",
              textWrap: "pretty"
            }}>
              Build enterprise-wide AI training programs for Claude, ChatGPT Enterprise, Microsoft Copilot, Gemini, GitHub Copilot, and internal tools — with role-based labs, governance, and adoption support that turns access into capability.
            </p>

            <form
              className="hero-email-form"
              onSubmit={(e) => {
                e.preventDefault();
                const f = e.currentTarget;
                const email = f.elements.email.value.trim();
                if (!email) return;
                // For now: route to mail compose with the work email prefilled.
                window.location.href = `mailto:contact@ajaia.ai?subject=Enterprise%20AI%20training%20enquiry&body=Work%20email%3A%20${encodeURIComponent(email)}%0D%0A%0D%0AI%27d%20like%20to%20talk%20about%20enterprise%20AI%20training%20for%20my%20team.`;
              }}
              style={{
                marginTop: 36,
                display: "flex", alignItems: "stretch", gap: 0,
                maxWidth: 560,
                background: "linear-gradient(180deg, rgba(255,255,255,0.10) 0%, rgba(255,255,255,0.04) 100%)",
                border: "1px solid rgba(255,255,255,0.22)",
                backdropFilter: "blur(14px)",
                WebkitBackdropFilter: "blur(14px)",
                boxShadow: "0 18px 40px -18px rgba(0,12,55,0.55), inset 0 1px 0 rgba(255,255,255,0.10)",
                padding: 6,
                position: "relative",
              }}>
              <label htmlFor="hero-email" style={{
                display: "inline-flex", alignItems: "center", gap: 10,
                paddingLeft: 14, paddingRight: 8,
                color: "rgba(255,255,255,0.55)",
                pointerEvents: "none",
              }}>
                <svg width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1.5">
                  <rect x="1.5" y="3" width="13" height="10" />
                  <path d="M1.5 3.5l6.5 5 6.5-5" strokeLinecap="round" />
                </svg>
              </label>
              <input
                id="hero-email"
                name="email"
                type="email"
                required
                placeholder="Your work email"
                autoComplete="email"
                style={{
                  flex: 1, minWidth: 0,
                  height: 52,
                  border: "none", outline: "none", background: "transparent",
                  color: "white",
                  fontFamily: "var(--font-sans)", fontWeight: 500, fontSize: 15.5,
                  letterSpacing: "-0.005em",
                  padding: "0 8px",
                }} />
              <button type="submit" className="aj-cta" style={{
                display: "inline-flex", alignItems: "center", gap: 10,
                height: 52, padding: "0 22px",
                background: "var(--sky-400)", color: "var(--ink-900)",
                border: "none", cursor: "pointer",
                fontFamily: "var(--font-sans)", fontWeight: 600, fontSize: 15,
                letterSpacing: "-0.01em", whiteSpace: "nowrap",
                position: "relative", overflow: "hidden",
                boxShadow: "0 0 0 1px rgba(151,194,247,0.5), 0 0 30px -8px rgba(151,194,247,0.55)",
              }}>
                Learn more
                <AjIcon.ArrowRight size={15} />
              </button>
            </form>

          </div>

          {/* RIGHT — Training console with the AI platform stack orbiting in */}
          <div className="hero-visual" style={{ position: "relative", height: 600, minWidth: 0, width: "100%" }}>
            <TrainingVisual />
          </div>
        </div>
      </div>

      <style>{`
        .orb-frame {
          position: relative;
          width: 400px; height: 400px;
          border-radius: 32px;
          background:
            radial-gradient(ellipse at 50% 50%, rgba(59,109,245,0.20) 0%, rgba(10,21,48,0) 60%),
            linear-gradient(180deg, rgba(59,109,245,0.10) 0%, rgba(0,0,0,0) 50%, rgba(30,58,138,0.15) 100%);
          border: 1px solid rgba(151,194,247,0.10);
          overflow: visible;
        }
        .orb-halo {
          position: absolute;
          width: 560px; height: 560px;
          border-radius: 50%;
          background: radial-gradient(circle, rgba(59,109,245,0.32) 0%, rgba(59,109,245,0) 65%);
          filter: blur(40px);
          opacity: 0.85;
          animation: orbBreathe 6s ease-in-out infinite;
        }
        @keyframes orbBreathe {
          0%, 100% { transform: scale(1);   opacity: 0.80; }
          50%      { transform: scale(1.08); opacity: 1; }
        }
        .breathe-glow {
          transform-origin: 200px 215px;
          animation: centerBreathe 5s ease-in-out infinite;
        }
        @keyframes centerBreathe {
          0%, 100% { transform: scale(0.95); opacity: 0.85; }
          50%      { transform: scale(1.10); opacity: 1; }
        }
        .ring-rotate {
          transform-origin: 200px 215px;
          animation: ringDrift 60s linear infinite;
        }
        @keyframes ringDrift {
          from { transform: rotate(0deg); }
          to   { transform: rotate(360deg); }
        }
        .node-pulse {
          transform-origin: center;
          animation: nodePulse 3.6s ease-out infinite;
        }
        @keyframes nodePulse {
          0%   { transform: scale(0.85); opacity: 0.85; }
          70%  { transform: scale(1.6);  opacity: 0;    }
          100% { transform: scale(1.6);  opacity: 0;    }
        }
        .node-pop {
          transform-origin: center;
          opacity: 0;
          animation: nodePop 700ms cubic-bezier(0.22, 1, 0.36, 1) forwards;
        }
        @keyframes nodePop {
          0%   { transform: scale(0.4); opacity: 0; }
          100% { transform: scale(1);   opacity: 1; }
        }
        .edge-fade {
          stroke-dasharray: 200;
          stroke-dashoffset: 200;
          animation: edgeDraw 1200ms cubic-bezier(0.22, 1, 0.36, 1) forwards;
          opacity: 0;
        }
        @keyframes edgeDraw {
          0%   { stroke-dashoffset: 200; opacity: 0; }
          40%  { opacity: 0.55; }
          100% { stroke-dashoffset: 0;   opacity: 0.55; }
        }
        .widget-enter {
          opacity: 0;
          transform: translateY(16px) scale(0.94);
          animation: widgetIn 700ms cubic-bezier(0.22, 1, 0.36, 1) forwards;
          will-change: transform, opacity;
        }
        @keyframes widgetIn {
          to { opacity: 1; transform: translateY(0) scale(1); }
        }
        .bar-rise {
          transform-origin: bottom;
          transform: scaleY(0);
          animation: barRise 700ms cubic-bezier(0.22, 1, 0.36, 1) forwards;
        }
        @keyframes barRise { to { transform: scaleY(1); } }
        .grow-bar {
          transform-origin: left;
          transform: scaleX(0);
          animation: barGrow 1200ms cubic-bezier(0.22, 1, 0.36, 1) forwards;
        }
        @keyframes barGrow { to { transform: scaleX(1); } }

        @media (prefers-reduced-motion: reduce) {
          .orb-halo, .breathe-glow, .ring-rotate,
          .node-pulse, .node-pop, .edge-fade,
          .widget-enter, .bar-rise, .grow-bar,
          .float-1, .float-2, .float-3 {
            animation: none !important;
            transform: none !important;
            opacity: 1 !important;
            stroke-dashoffset: 0 !important;
          }
        }

        @media (max-width: 1024px) {
          .hero-grid { grid-template-columns: 1fr !important; gap: 80px !important; justify-items: center !important; }
          .hero-visual { height: 520px !important; max-width: 560px; width: 100% !important; margin: 0 auto !important; justify-self: center !important; }
          .reveal { width: 100%; max-width: 640px; }
        }
        @media (max-width: 760px) {
          .stats-strip { flex-wrap: wrap !important; gap: 20px !important; }
          .stats-strip > div { flex-basis: calc(50% - 12px) !important; border-right: none !important; padding-right: 0 !important; }
        }
        @media (max-width: 640px) {
          .hero-visual { height: 440px !important; }
          .orb-frame { width: 320px !important; height: 320px !important; }
          .orb-halo  { width: 440px !important; height: 440px !important; }
          .hero-ctas { flex-wrap: wrap !important; }
          .hero-email-form { flex-wrap: wrap !important; padding: 10px !important; }
          .hero-email-form input { width: 100% !important; height: 44px !important; }
          .hero-email-form button { width: 100% !important; justify-content: center !important; }
          .hero-email-form label { display: none !important; }
        }
        .hero-email-form:focus-within {
          border-color: rgba(151,194,247,0.45) !important;
          box-shadow: 0 18px 40px -18px rgba(0,12,55,0.55), inset 0 1px 0 rgba(255,255,255,0.10), 0 0 0 3px rgba(151,194,247,0.12) !important;
        }
        .hero-email-form input::placeholder {
          color: rgba(255,255,255,0.42);
        }
        .hero-email-form button:hover { filter: brightness(1.05); }
        .hero-email-form button:active { transform: scale(0.985); }
      `}</style>
    </section>);

}

Object.assign(window, { Hero });
