/* global React */
// Hero RIGHT visual — Ajaia AI Training (editorial illustration)
// ─────────────────────────────────────────────────────────────────
// A single, simple SVG illustration that reads as a SERVICE — not
// a product mockup. Composition:
//   · A glowing AI emblem (hexagon with internal knowledge graph)
//   · Three cohort figures (silhouettes) arranged in a gentle arc
//     beneath it, connected by thin "knowledge transfer" lines
//   · A soft navy halo backdrop with the brand 18×18 squares accent
//   · Small platform mini-badges (Claude, ChatGPT, Gemini, Copilot,
//     GitHub Copilot) floating around the perimeter as accents —
//     they communicate "all major AI platforms" without dominating.
// No fake UI, no fake numbers, no widgets. Just an illustration.

const { useEffect: useEffectHV } = React;

// ─── Platform glyphs (small, used as floating mini-badges) ─────────
const PlatformGlyph = {
  Claude: ({ size = 22 }) => (
    <img
      src={window.__resources && window.__resources.claudeLogo}
      alt="Claude"
      width={size}
      height={size}
      style={{ display: "block", objectFit: "contain" }}
    />
  ),
  ChatGPT: ({ size = 22 }) => (
    <svg width={size} height={size} viewBox="0 0 32 32" fill="none">
      <circle cx="16" cy="16" r="13" fill="#10A37F" />
      <path d="M16 8.5 L21.5 11.5 L21.5 17.5 L16 20.5 L10.5 17.5 L10.5 11.5 Z"
        stroke="white" strokeWidth="1.6" fill="none" strokeLinejoin="round" />
      <path d="M16 8.5 L16 14 M21.5 11.5 L16 14 M10.5 11.5 L16 14"
        stroke="white" strokeWidth="1.6" strokeLinecap="round" />
    </svg>
  ),
  Gemini: ({ size = 22 }) => (
    <svg width={size} height={size} viewBox="0 0 32 32" fill="none">
      <defs>
        <linearGradient id="gemG2" x1="0%" y1="0%" x2="100%" y2="100%">
          <stop offset="0%"   stopColor="#4796E3" />
          <stop offset="50%"  stopColor="#1B72E8" />
          <stop offset="100%" stopColor="#8054D9" />
        </linearGradient>
      </defs>
      <path d="M16 3 C16 11 19 14 27 16 C19 18 16 21 16 29 C16 21 13 18 5 16 C13 14 16 11 16 3 Z"
        fill="url(#gemG2)" />
    </svg>
  ),
  Copilot: ({ size = 22 }) => (
    <svg width={size} height={size} viewBox="0 0 32 32" fill="none">
      <circle cx="16" cy="16" r="13" fill="#0F4FB0" />
      <path d="M9 18 Q9 12 14 12 L17 12 Q22 12 22 17 Q22 22 17 22 L13 22"
        stroke="#5DB7FF" strokeWidth="2" fill="none" strokeLinecap="round" />
      <circle cx="13" cy="16.5" r="1.5" fill="white" />
      <circle cx="19" cy="16.5" r="1.5" fill="white" />
    </svg>
  ),
  GitHub: ({ size = 22 }) => (
    <svg width={size} height={size} viewBox="0 0 32 32" fill="none">
      <circle cx="16" cy="16" r="13" fill="#0D1117" />
      <path d="M16 8 C11.6 8 8 11.7 8 16.3 C8 19.9 10.3 23 13.5 24.1 C13.9 24.2 14 23.95 14 23.75 L14 22.5 C11.8 23 11.3 21.4 11.3 21.4 C10.9 20.5 10.4 20.2 10.4 20.2 C9.7 19.7 10.5 19.7 10.5 19.7 C11.3 19.8 11.7 20.5 11.7 20.5 C12.4 21.8 13.6 21.4 14 21.2 C14.1 20.7 14.3 20.4 14.5 20.2 C12.7 20 10.9 19.3 10.9 16 C10.9 15 11.3 14.2 11.7 13.6 C11.7 13.4 11.3 12.5 11.8 11.2 C11.8 11.2 12.5 11 14 12.1 C14.7 11.9 15.4 11.8 16 11.8 C16.7 11.8 17.4 11.9 18 12.1 C19.5 11 20.2 11.2 20.2 11.2 C20.7 12.5 20.4 13.4 20.3 13.6 C20.8 14.2 21.1 15 21.1 16 C21.1 19.3 19.3 20 17.5 20.2 C17.8 20.5 18 21 18 21.8 L18 23.75 C18 23.95 18.1 24.2 18.5 24.1 C21.7 23 24 19.9 24 16.3 C24 11.7 20.4 8 16 8 Z"
        fill="white" />
    </svg>
  ),
};

// ─── Platform mini-badge ───────────────────────────────────────────
// Small, restrained — a frosted disc with the platform glyph inside.
// Outer wrapper handles absolute positioning; inner wrapper carries
// the float animation. This separation prevents transform conflicts
// (e.g. when we need translateX(-50%) for centering).
function PlatformBadge({ GlyphCmp, label, wrapperStyle, delay = 0, floatClass = "float-1" }) {
  const [shown, setShown] = React.useState(false);
  React.useEffect(() => {
    const t = setTimeout(() => setShown(true), delay);
    return () => clearTimeout(t);
  }, [delay]);

  return (
    <div
      style={{
        position: "absolute",
        opacity: shown ? 1 : 0,
        transform: shown ? "translateY(0)" : "translateY(8px)",
        transition: "opacity 600ms cubic-bezier(0.22, 1, 0.36, 1), transform 600ms cubic-bezier(0.22, 1, 0.36, 1)",
        zIndex: 5,
        ...wrapperStyle,
      }}>
      <div
        className={`platform-mini ${floatClass}`}
        style={{
          display: "flex", alignItems: "center", gap: 8,
          padding: "6px 11px 6px 6px",
          background: "linear-gradient(180deg, rgba(255,255,255,0.18) 0%, rgba(255,255,255,0.06) 100%)",
          border: "1px solid rgba(255,255,255,0.28)",
          backdropFilter: "blur(18px) saturate(160%)",
          WebkitBackdropFilter: "blur(18px) saturate(160%)",
          borderRadius: 999,
          boxShadow: "0 14px 30px -14px rgba(0,12,55,0.55), inset 0 1px 0 rgba(255,255,255,0.30)",
        }}>
        <div style={{
          width: 28, height: 28, borderRadius: "50%",
          background: "white",
          display: "grid", placeItems: "center",
          boxShadow: "0 3px 8px -2px rgba(0,0,0,0.20)",
          flexShrink: 0,
        }}>
          <GlyphCmp size={20} />
        </div>
        <div style={{
          fontFamily: "var(--font-sans)", fontWeight: 600, fontSize: 11.5,
          color: "white", letterSpacing: "-0.005em", whiteSpace: "nowrap",
        }}>{label}</div>
      </div>
    </div>
  );
}

function TrainingVisual() {
  return (
    <div className="train-visual" style={{
      position: "absolute", inset: 0,
      display: "grid", placeItems: "center",
      overflow: "hidden",
    }}>
      {/* Soft backdrop halo */}
      <div className="train-halo" aria-hidden="true" />

      {/* Illustration */}
      <svg
        className="train-svg"
        viewBox="0 0 600 600"
        width="100%"
        height="100%"
        preserveAspectRatio="xMidYMid meet"
        style={{ position: "relative", zIndex: 2, maxWidth: 640 }}
        role="img"
        aria-label="Ajaia AI training: a glowing AI emblem connecting to three cohort figures">
        <defs>
          {/* Sky-blue gradient for the AI mark */}
          <linearGradient id="aiFace" x1="0%" y1="0%" x2="100%" y2="100%">
            <stop offset="0%"   stopColor="#B6D4FA" />
            <stop offset="50%"  stopColor="#97C2F8" />
            <stop offset="100%" stopColor="#3B6DF5" />
          </linearGradient>

          {/* Cohort figure fills */}
          <linearGradient id="figPrimary" x1="0%" y1="0%" x2="0%" y2="100%">
            <stop offset="0%"   stopColor="#1F3FAA" />
            <stop offset="100%" stopColor="#0B2486" />
          </linearGradient>
          <linearGradient id="figSecondary" x1="0%" y1="0%" x2="0%" y2="100%">
            <stop offset="0%"   stopColor="#3B6DF5" />
            <stop offset="100%" stopColor="#1F3FAA" />
          </linearGradient>

          {/* Soft glow filter */}
          <filter id="softGlow" x="-30%" y="-30%" width="160%" height="160%">
            <feGaussianBlur stdDeviation="6" result="b" />
            <feMerge>
              <feMergeNode in="b" />
              <feMergeNode in="SourceGraphic" />
            </feMerge>
          </filter>

          {/* Halo glow behind AI mark */}
          <radialGradient id="markHalo" cx="50%" cy="50%" r="50%">
            <stop offset="0%"   stopColor="rgba(151,194,247,0.55)" />
            <stop offset="60%"  stopColor="rgba(86,131,255,0.15)" />
            <stop offset="100%" stopColor="rgba(7,16,58,0)" />
          </radialGradient>
        </defs>

        {/* ─── Background: concentric rings (very subtle) ─── */}
        <g className="ring-drift">
          <circle cx="300" cy="270" r="240" fill="none"
            stroke="rgba(151,194,247,0.12)" strokeDasharray="2 8" />
          <circle cx="300" cy="270" r="180" fill="none"
            stroke="rgba(151,194,247,0.18)" strokeDasharray="2 8" />
        </g>

        {/* ─── AI emblem glow ─── */}
        <circle cx="300" cy="180" r="110" fill="url(#markHalo)" className="emblem-breathe" />

        {/* ─── Connection lines: AI emblem → each cohort figure ─── */}
        <g stroke="rgba(151,194,247,0.55)" strokeWidth="1.2" fill="none"
           strokeDasharray="4 6" strokeLinecap="round">
          {/* to left figure */}
          <path d="M 270 215 Q 220 290 165 365" className="link-1" />
          {/* to center figure */}
          <path d="M 300 220 Q 300 285 300 360" className="link-2" />
          {/* to right figure */}
          <path d="M 330 215 Q 380 290 435 365" className="link-3" />
        </g>

        {/* ─── Travelling spark packets along each connector ─── */}
        <g>
          {[
            "M 270 215 Q 220 290 165 365",
            "M 300 220 Q 300 285 300 360",
            "M 330 215 Q 380 290 435 365",
          ].map((d, i) => (
            <g key={i}>
              <circle r="4" fill="rgba(151,194,247,0.35)" filter="url(#softGlow)">
                <animateMotion dur="3.6s" begin={`${0.4 + i * 0.6}s`}
                  repeatCount="indefinite" path={d} />
                <animate attributeName="opacity"
                  values="0;1;1;0" keyTimes="0;0.15;0.85;1"
                  dur="3.6s" begin={`${0.4 + i * 0.6}s`}
                  repeatCount="indefinite" />
              </circle>
              <circle r="1.8" fill="#DCE9FF">
                <animateMotion dur="3.6s" begin={`${0.4 + i * 0.6}s`}
                  repeatCount="indefinite" path={d} />
                <animate attributeName="opacity"
                  values="0;1;1;0" keyTimes="0;0.15;0.85;1"
                  dur="3.6s" begin={`${0.4 + i * 0.6}s`}
                  repeatCount="indefinite" />
              </circle>
            </g>
          ))}
        </g>

        {/* ─── AI emblem (hexagon with internal knowledge graph) ─── */}
        <g className="emblem-float" style={{ transformOrigin: "300px 180px" }}>
          {/* Hexagon body */}
          <path d="M 300 120 L 354 152 L 354 208 L 300 240 L 246 208 L 246 152 Z"
            fill="url(#aiFace)"
            stroke="rgba(255,255,255,0.45)" strokeWidth="1.2"
            filter="url(#softGlow)" />

          {/* Subtle inner edge */}
          <path d="M 300 130 L 346 156 L 346 204 L 300 230 L 254 204 L 254 156 Z"
            fill="none"
            stroke="rgba(255,255,255,0.20)" strokeWidth="1" />

          {/* Internal nodes + connections (knowledge graph) */}
          <g stroke="white" strokeWidth="1.3" strokeLinecap="round">
            <line x1="300" y1="160" x2="282" y2="180" opacity="0.7" />
            <line x1="300" y1="160" x2="318" y2="180" opacity="0.7" />
            <line x1="282" y1="180" x2="300" y2="200" opacity="0.7" />
            <line x1="318" y1="180" x2="300" y2="200" opacity="0.7" />
          </g>
          <g fill="white">
            <circle cx="300" cy="160" r="3.2" />
            <circle cx="282" cy="180" r="3.2" />
            <circle cx="318" cy="180" r="3.2" />
            <circle cx="300" cy="200" r="4.2" fill="#FFFFE6" className="center-pulse" />
          </g>
        </g>

        {/* ─── Three cohort figures (silhouettes) ─── */}
        {/* Each figure: rounded head + rounded-trapezoid shoulders. */}
        {/* Center figure is the lead (slightly larger + cream halo). */}

        {/* — Left figure — */}
        <g className="fig fig-left" style={{ transformOrigin: "165px 400px" }}>
          {/* Subtle floor ellipse */}
          <ellipse cx="165" cy="510" rx="46" ry="6" fill="rgba(151,194,247,0.18)" />
          {/* Body */}
          <path
            d="M 120 510 C 120 475 138 460 165 460 C 192 460 210 475 210 510 Z"
            fill="url(#figSecondary)" />
          {/* Head */}
          <circle cx="165" cy="430" r="26" fill="url(#figSecondary)" />
          {/* Rim light on head */}
          <path d="M 144 422 A 26 26 0 0 1 175 408"
            stroke="rgba(220,233,255,0.35)" strokeWidth="2" fill="none" strokeLinecap="round" />
        </g>

        {/* — Center figure (lead) — */}
        <g className="fig fig-center" style={{ transformOrigin: "300px 400px" }}>
          {/* Cream halo behind head (the cream-100 spice — once per view) */}
          <circle cx="300" cy="410" r="42" fill="rgba(255,255,230,0.10)" />
          {/* Floor */}
          <ellipse cx="300" cy="514" rx="58" ry="7" fill="rgba(151,194,247,0.22)" />
          {/* Body */}
          <path
            d="M 246 514 C 246 472 270 452 300 452 C 330 452 354 472 354 514 Z"
            fill="url(#figPrimary)" />
          {/* Head */}
          <circle cx="300" cy="416" r="32" fill="url(#figPrimary)" />
          {/* Cream rim light (signature accent) */}
          <path d="M 276 408 A 32 32 0 0 1 312 392"
            stroke="rgba(255,255,230,0.55)" strokeWidth="2.2" fill="none" strokeLinecap="round" />
        </g>

        {/* — Right figure — */}
        <g className="fig fig-right" style={{ transformOrigin: "435px 400px" }}>
          <ellipse cx="435" cy="510" rx="46" ry="6" fill="rgba(151,194,247,0.18)" />
          <path
            d="M 390 510 C 390 475 408 460 435 460 C 462 460 480 475 480 510 Z"
            fill="url(#figSecondary)" />
          <circle cx="435" cy="430" r="26" fill="url(#figSecondary)" />
          <path d="M 414 422 A 26 26 0 0 1 445 408"
            stroke="rgba(220,233,255,0.35)" strokeWidth="2" fill="none" strokeLinecap="round" />
        </g>

        {/* ─── Brand 18×18 squares accent (two offset pairs) ─── */}
        <g opacity="0.55">
          <rect x="68"  y="100" width="14" height="14" fill="#97C2F8" />
          <rect x="78"  y="110" width="14" height="14" fill="none"
            stroke="#97C2F8" strokeWidth="1" />
        </g>
        <g opacity="0.55">
          <rect x="508" y="498" width="14" height="14" fill="none"
            stroke="#97C2F8" strokeWidth="1" />
          <rect x="518" y="508" width="14" height="14" fill="#97C2F8" />
        </g>

        {/* ─── Floating sparkle particles around the emblem ─── */}
        <g fill="#DCE9FF" opacity="0.85">
          <circle cx="220" cy="135" r="1.6" className="spark s1" />
          <circle cx="380" cy="120" r="2"   className="spark s2" />
          <circle cx="395" cy="240" r="1.4" className="spark s3" />
          <circle cx="200" cy="240" r="1.8" className="spark s4" />
          <circle cx="300" cy="80"  r="1.6" className="spark s5" />
        </g>
      </svg>

      {/* ─── Platform mini-badges (Claude, ChatGPT, Gemini, Copilot, GitHub) ─── */}
      {/* Positioned around the illustration as accent — communicates the
          multi-tool scope of Ajaia's training without overpowering the
          illustration. */}
      <PlatformBadge floatClass="float-1" delay={500}
        GlyphCmp={PlatformGlyph.Claude} label="Claude"
        wrapperStyle={{ left: "4%", top: "14%" }} />

      <PlatformBadge floatClass="float-2" delay={700}
        GlyphCmp={PlatformGlyph.ChatGPT} label="ChatGPT"
        wrapperStyle={{ right: "4%", top: "10%" }} />

      <PlatformBadge floatClass="float-3" delay={900}
        GlyphCmp={PlatformGlyph.Gemini} label="Gemini"
        wrapperStyle={{ left: "2%", top: "44%" }} />

      <PlatformBadge floatClass="float-1" delay={1100}
        GlyphCmp={PlatformGlyph.Copilot} label="M365 Copilot"
        wrapperStyle={{ right: "2%", top: "44%" }} />

      <PlatformBadge floatClass="float-2" delay={1300}
        GlyphCmp={PlatformGlyph.GitHub} label="GitHub Copilot"
        wrapperStyle={{ left: "50%", bottom: "4%", transform: "translateX(-50%)" }} />

      <style>{`
        .train-halo {
          position: absolute;
          width: 640px; height: 640px;
          border-radius: 50%;
          background:
            radial-gradient(circle at 50% 45%, rgba(59,109,245,0.30) 0%, rgba(59,109,245,0) 60%);
          filter: blur(50px);
          opacity: 0.85;
          animation: haloBreathe 7s ease-in-out infinite;
          z-index: 0;
        }
        @keyframes haloBreathe {
          0%, 100% { transform: scale(1);   opacity: 0.80; }
          50%      { transform: scale(1.05); opacity: 1; }
        }

        .ring-drift {
          transform-origin: 300px 270px;
          animation: ringDrift 80s linear infinite;
        }
        @keyframes ringDrift {
          from { transform: rotate(0deg); }
          to   { transform: rotate(360deg); }
        }

        .emblem-breathe {
          transform-origin: 300px 180px;
          animation: emblemBreathe 5s ease-in-out infinite;
        }
        @keyframes emblemBreathe {
          0%, 100% { transform: scale(0.95); opacity: 0.85; }
          50%      { transform: scale(1.10); opacity: 1; }
        }
        .emblem-float {
          animation: emblemFloat 6s ease-in-out infinite;
        }
        @keyframes emblemFloat {
          0%, 100% { transform: translateY(0); }
          50%      { transform: translateY(-6px); }
        }
        .center-pulse {
          transform-origin: 300px 200px;
          animation: centerPulse 2.4s ease-in-out infinite;
        }
        @keyframes centerPulse {
          0%, 100% { transform: scale(1);   opacity: 1; }
          50%      { transform: scale(1.35); opacity: 0.7; }
        }

        .fig {
          opacity: 0;
          transform: translateY(20px);
          animation: figIn 900ms cubic-bezier(0.22, 1, 0.36, 1) forwards;
        }
        .fig-left   { animation-delay: 300ms; }
        .fig-center { animation-delay: 100ms; }
        .fig-right  { animation-delay: 500ms; }
        @keyframes figIn {
          to { opacity: 1; transform: translateY(0); }
        }

        .link-1, .link-2, .link-3 {
          stroke-dasharray: 4 6;
          stroke-dashoffset: 200;
          animation: linkDraw 1400ms cubic-bezier(0.22, 1, 0.36, 1) forwards;
          opacity: 0;
        }
        .link-1 { animation-delay: 600ms; }
        .link-2 { animation-delay: 400ms; }
        .link-3 { animation-delay: 800ms; }
        @keyframes linkDraw {
          0%   { stroke-dashoffset: 200; opacity: 0; }
          40%  { opacity: 0.7; }
          100% { stroke-dashoffset: 0;   opacity: 0.7; }
        }

        .spark {
          animation: sparkPulse 3s ease-in-out infinite;
        }
        .spark.s1 { animation-delay: 0.0s; }
        .spark.s2 { animation-delay: 0.6s; }
        .spark.s3 { animation-delay: 1.2s; }
        .spark.s4 { animation-delay: 1.8s; }
        .spark.s5 { animation-delay: 2.4s; }
        @keyframes sparkPulse {
          0%, 100% { opacity: 0.2; transform: scale(0.8); }
          50%      { opacity: 1;   transform: scale(1.2); }
        }

        @media (prefers-reduced-motion: reduce) {
          .train-halo, .ring-drift, .emblem-breathe, .emblem-float,
          .center-pulse, .fig, .link-1, .link-2, .link-3, .spark {
            animation: none !important;
            transform: none !important;
            opacity: 1 !important;
            stroke-dashoffset: 0 !important;
          }
        }

        @media (max-width: 1024px) {
          .train-halo { width: 520px !important; height: 520px !important; }
        }
        @media (max-width: 760px) {
          .train-svg { max-width: 460px !important; }
          .train-halo { width: 400px !important; height: 400px !important; }
        }
      `}</style>
    </div>
  );
}

Object.assign(window, { TrainingVisual, PlatformGlyph });
