/* global React */
/* Hand-drawn SVG art slots for each work item.
   All animations use CSS keyframes scoped via classNames in styles.css.
   Stroke colors map to currentColor (set per-item via wrapper). */

// 1) OTA — landscape mountains + phone with map navigation pin moving along a path
function ArtOTA() {
  return (
    <svg className="work-art-svg" viewBox="0 0 280 180" fill="none" aria-hidden="true">
      <defs>
        <linearGradient id="ota-sky" x1="0" x2="0" y1="0" y2="1">
          <stop offset="0" stopColor="currentColor" stopOpacity="0.04" />
          <stop offset="1" stopColor="currentColor" stopOpacity="0" />
        </linearGradient>
        <clipPath id="ota-frame">
          <rect x="14" y="14" width="252" height="152" rx="10" />
        </clipPath>
      </defs>
      <rect x="14" y="14" width="252" height="152" rx="10" fill="url(#ota-sky)" stroke="currentColor" strokeOpacity="0.18" />
      <g clipPath="url(#ota-frame)">
        {/* sun */}
        <circle cx="78" cy="58" r="11" stroke="currentColor" strokeOpacity="0.5" strokeWidth="1.2" />
        {/* far range */}
        <path d="M14 110 L46 78 L70 92 L100 64 L132 86 L160 70 L196 90 L226 76 L266 100 L266 166 L14 166 Z"
          stroke="currentColor" strokeOpacity="0.35" strokeWidth="1.2" fill="currentColor" fillOpacity="0.04" />
        {/* near range */}
        <path d="M14 132 L40 116 L66 124 L94 104 L120 122 L150 110 L180 124 L208 112 L240 124 L266 116 L266 166 L14 166 Z"
          stroke="currentColor" strokeWidth="1.4" fill="currentColor" fillOpacity="0.07" />
        {/* water ripples */}
        <g className="art-ota-ripples" stroke="currentColor" strokeOpacity="0.35" strokeWidth="1">
          <path d="M22 148 q12 -3 24 0 t24 0 t24 0" />
          <path d="M120 154 q14 -3 28 0 t28 0 t28 0" />
        </g>
        {/* small bird */}
        <path className="art-ota-bird" d="M0 0 q4 -4 8 0 q4 -4 8 0" stroke="currentColor" strokeWidth="1.2" />
      </g>
      {/* phone — bottom right, overlapping the frame */}
      <g transform="translate(178 82)">
        <rect x="0" y="0" width="64" height="92" rx="9" fill="currentColor" fillOpacity="0.06" stroke="currentColor" strokeWidth="1.4" />
        <rect x="4" y="4" width="56" height="84" rx="6" fill="var(--bg)" stroke="currentColor" strokeOpacity="0.22" />
        <line x1="26" y1="7" x2="38" y2="7" stroke="currentColor" strokeOpacity="0.35" strokeWidth="1" />
        {/* map path inside phone — animated dash march */}
        <path className="art-ota-route"
          d="M10 76 C 18 64, 14 52, 24 44 S 44 36, 50 22 L 54 14"
          stroke="currentColor" strokeOpacity="0.55" strokeWidth="1.4" fill="none" />
        {/* destinations */}
        <circle cx="10" cy="76" r="1.8" fill="currentColor" />
        <circle cx="54" cy="14" r="2.6" fill="currentColor" />
        {/* pulse on destination */}
        <circle className="art-ota-pulse" cx="54" cy="14" r="2.6" fill="none" stroke="currentColor" strokeWidth="1.2" />
        {/* moving pin — travels along the route inside the phone */}
        <g className="art-ota-pin">
          <circle r="2.6" fill="currentColor" stroke="var(--bg)" strokeWidth="1" />
          <animateMotion
            dur="6s"
            repeatCount="indefinite"
            keyTimes="0;0.12;0.86;1"
            keyPoints="0;0;1;1"
            calcMode="linear"
            path="M10 76 C 18 64, 14 52, 24 44 S 44 36, 50 22 L 54 14"
          />
        </g>
      </g>
    </svg>);
}

// 2) Fintech — 5 watering cans tilting in sequence onto one central tree
function ArtFintech() {
  return (
    <svg className="work-art-svg" viewBox="0 0 280 180" fill="none" aria-hidden="true">
      <rect x="14" y="14" width="252" height="152" rx="10" fill="currentColor" fillOpacity="0.03" stroke="currentColor" strokeOpacity="0.18" />
      {/* ground line */}
      <path d="M30 150 L250 150" stroke="currentColor" strokeOpacity="0.4" strokeWidth="1.2" />
      <ellipse cx="140" cy="154" rx="50" ry="3.5" fill="currentColor" fillOpacity="0.08" />
      {/* tree — animated grow, anchored to ground */}
      <g transform="translate(140 150)">
        <g className="art-tree-inner">
          <path d="M0 0 L0 -34" stroke="currentColor" strokeWidth="1.8" />
          <path d="M0 -14 q-7 -4 -12 -2" stroke="currentColor" strokeWidth="1.2" />
          <path d="M0 -22 q8 -4 13 -2" stroke="currentColor" strokeWidth="1.2" />
          <circle cx="-12" cy="-20" r="5" fill="currentColor" fillOpacity="0.16" stroke="currentColor" strokeWidth="1.1" />
          <circle cx="13" cy="-26" r="5.5" fill="currentColor" fillOpacity="0.16" stroke="currentColor" strokeWidth="1.1" />
          <circle cx="0" cy="-38" r="9" fill="currentColor" fillOpacity="0.2" stroke="currentColor" strokeWidth="1.4" />
          <circle cx="-3" cy="-40" r="1.4" fill="currentColor" />
          <circle cx="4" cy="-36" r="1" fill="currentColor" />
          <animateTransform
            attributeName="transform"
            type="scale"
            values="0.4;1;0.4"
            keyTimes="0;0.5;1"
            dur="8s"
            repeatCount="indefinite"
            additive="replace"
          />
        </g>
      </g>
      {/* 5 cans arranged across the top, all spouts angled toward tree (140, 110-ish) */}
      {[
        { i: 0, x: 50,  flip: false, ang: 28 },
        { i: 1, x: 92,  flip: false, ang: 18 },
        { i: 2, x: 140, flip: false, ang: 0 },
        { i: 3, x: 188, flip: true,  ang: -18 },
        { i: 4, x: 230, flip: true,  ang: -28 },
      ].map(({ i, x, flip, ang }) => {
        // For "flip" cans (right side), mirror horizontally so spout points left/inward
        const baseY = 56;
        return (
          <g key={i} transform={`translate(${x} ${baseY})`} className={`art-can art-can-${i}`}>
            <g className="art-can-body" transform={flip ? 'scale(-1 1)' : ''}>
              {/* body */}
              <rect x="-9" y="-7" width="18" height="13" rx="2" fill="currentColor" fillOpacity="0.06" stroke="currentColor" strokeWidth="1.3" />
              {/* handle (top arch) */}
              <path d="M-7 -7 q0 -7 7 -7 q7 0 7 7" stroke="currentColor" strokeWidth="1.2" fill="none" />
              {/* spout */}
              <path d="M9 -5 L 16 -8 L 18 -5 L 11 -1 Z" fill="currentColor" fillOpacity="0.18" stroke="currentColor" strokeWidth="1.2" />
              {/* shower nozzle */}
              <line x1="16" y1="-8" x2="19" y2="-9.5" stroke="currentColor" strokeWidth="1.2" />
            </g>
            {/* drops — fall toward tree center; computed per-can */}
            <g className="art-drops" style={{
              // for each can, build a translation toward (140 - x, 110 - baseY) = (140-x, 54)
              // we use CSS variables so keyframes can interpolate
              ['--dx']: `${140 - x}px`,
              ['--dy']: `${110 - baseY}px`,
            }}>
              <circle cx="0" cy="0" r="1.4" fill="currentColor" />
              <circle cx="2" cy="3" r="1.1" fill="currentColor" />
              <circle cx="-2" cy="6" r="0.9" fill="currentColor" />
            </g>
          </g>);
      })}
    </svg>);
}

// 3) Live-streaming — spinning wheel + danmaku stream
function ArtLive() {
  return (
    <svg className="work-art-svg" viewBox="0 0 280 180" fill="none" aria-hidden="true">
      <rect x="14" y="14" width="252" height="152" rx="10" fill="currentColor" fillOpacity="0.03" stroke="currentColor" strokeOpacity="0.18" />
      {/* spinning wheel — left */}
      <g transform="translate(72 90)">
        <circle r="44" stroke="currentColor" strokeOpacity="0.25" strokeWidth="1.2" />
        <g className="art-wheel">
          <circle r="38" stroke="currentColor" strokeWidth="1.4" />
          {/* 8 spokes */}
          {[0, 1, 2, 3, 4, 5, 6, 7].map((i) => {
            const a = (i * Math.PI) / 4;
            const x = Math.cos(a) * 38;
            const y = Math.sin(a) * 38;
            return <line key={i} x1="0" y1="0" x2={x.toFixed(2)} y2={y.toFixed(2)} stroke="currentColor" strokeOpacity="0.55" strokeWidth="1" />;
          })}
          {/* prize markers */}
          {[0, 1, 2, 3].map((i) => {
            const a = (i * Math.PI) / 2 + Math.PI / 4;
            const x = Math.cos(a) * 26;
            const y = Math.sin(a) * 26;
            return <circle key={i} cx={x.toFixed(2)} cy={y.toFixed(2)} r="2.6" fill="currentColor" />;
          })}
          <animateTransform
            attributeName="transform"
            type="rotate"
            values="0;900;900"
            keyTimes="0;0.6;1"
            dur="6s"
            repeatCount="indefinite"
            additive="replace"
          />
        </g>
        {/* pointer pin (fixed at top) */}
        <path d="M0 -50 L -5 -41 L 5 -41 Z" fill="currentColor" />
        {/* hub */}
        <circle r="4" fill="var(--bg)" stroke="currentColor" strokeWidth="1.4" />
      </g>

      {/* danmaku panel — right */}
      <g transform="translate(140 38)">
        <rect x="0" y="0" width="120" height="104" rx="6" fill="currentColor" fillOpacity="0.04" stroke="currentColor" strokeOpacity="0.25" />
        <defs>
          <clipPath id="dm-clip"><rect x="0" y="0" width="120" height="104" rx="6" /></clipPath>
        </defs>
        <g clipPath="url(#dm-clip)">
          {/* Each danmaku line scrolls right→left at staggered times */}
          <g className="art-dm art-dm-0">
            <rect x="0" y="0" width="62" height="10" rx="5" fill="currentColor" fillOpacity="0.18" />
            <text x="6" y="7.6" fontSize="6" fontFamily="var(--font-mono)" fill="currentColor" fillOpacity="0.95">★ awesome stream</text>
          </g>
          <g className="art-dm art-dm-1">
            <rect x="0" y="0" width="48" height="10" rx="5" fill="currentColor" fillOpacity="0.1" />
            <text x="6" y="7.6" fontSize="6" fontFamily="var(--font-mono)" fill="currentColor" fillOpacity="0.85">666 666</text>
          </g>
          <g className="art-dm art-dm-2">
            <rect x="0" y="0" width="74" height="10" rx="5" fill="currentColor" fillOpacity="0.14" />
            <text x="6" y="7.6" fontSize="6" fontFamily="var(--font-mono)" fill="currentColor" fillOpacity="0.95">+1 follow ♥</text>
          </g>
          <g className="art-dm art-dm-3">
            <rect x="0" y="0" width="56" height="10" rx="5" fill="currentColor" fillOpacity="0.1" />
            <text x="6" y="7.6" fontSize="6" fontFamily="var(--font-mono)" fill="currentColor" fillOpacity="0.85">gift sent ✦</text>
          </g>
          <g className="art-dm art-dm-4">
            <rect x="0" y="0" width="44" height="10" rx="5" fill="currentColor" fillOpacity="0.16" />
            <text x="6" y="7.6" fontSize="6" fontFamily="var(--font-mono)" fill="currentColor" fillOpacity="0.95">drop it!</text>
          </g>
        </g>
      </g>
    </svg>);
}

// 4) Casual game — platformer with hopping character + flag
function ArtGame() {
  return (
    <svg className="work-art-svg" viewBox="0 0 280 180" fill="none" aria-hidden="true">
      <rect x="14" y="14" width="252" height="152" rx="10" fill="currentColor" fillOpacity="0.03" stroke="currentColor" strokeOpacity="0.18" />
      {/* sky stars */}
      <g stroke="currentColor" strokeOpacity="0.4" strokeWidth="1">
        <path d="M44 38 L44 44 M41 41 L47 41" />
        <path d="M212 30 L212 36 M209 33 L215 33" />
        <path d="M118 24 L118 28 M116 26 L120 26" />
      </g>
      {/* clouds */}
      <g fill="currentColor" fillOpacity="0.06" stroke="currentColor" strokeOpacity="0.3" strokeWidth="1">
        <path d="M70 60 q4 -10 14 -8 q6 -8 16 -2 q8 -2 8 6 q0 6 -8 6 L78 62 q-6 0 -8 -2 Z" />
        <path d="M180 50 q5 -8 14 -6 q5 -6 12 -2 q7 -1 7 5 q0 5 -7 5 l-22 0 q-5 0 -4 -2 Z" />
      </g>
      {/* platforms */}
      <g stroke="currentColor" strokeWidth="1.6" fill="currentColor" fillOpacity="0.06">
        <rect x="22" y="118" width="58" height="10" rx="2" />
        <rect x="92" y="92" width="48" height="10" rx="2" />
        <rect x="154" y="118" width="44" height="10" rx="2" />
        <rect x="208" y="86" width="50" height="10" rx="2" />
      </g>
      {/* ? blocks */}
      <g fill="currentColor" fillOpacity="0.12" stroke="currentColor" strokeWidth="1.3">
        <rect x="116" y="64" width="14" height="14" rx="2" />
        <rect x="220" y="58" width="14" height="14" rx="2" />
      </g>
      <text x="119" y="75" fontSize="10" fontFamily="var(--font-mono)" fill="currentColor" fillOpacity="0.7">?</text>
      <text x="223" y="69" fontSize="10" fontFamily="var(--font-mono)" fill="currentColor" fillOpacity="0.7">?</text>
      {/* coins */}
      <g className="art-coins" fill="currentColor">
        <circle cx="108" cy="84" r="2.4" />
        <circle cx="124" cy="84" r="2.4" />
        <circle cx="172" cy="110" r="2.4" />
      </g>
      {/* finish flag */}
      <g transform="translate(248 86)">
        <line x1="0" y1="0" x2="0" y2="32" stroke="currentColor" strokeWidth="1.4" />
        <path d="M0 2 L 12 6 L 0 10 Z" fill="currentColor" fillOpacity="0.4" stroke="currentColor" strokeWidth="1.2" />
      </g>
      {/* hopping character */}
      <g className="art-hop" transform="translate(40 110)">
        <g>
          <rect x="-6" y="-10" width="12" height="12" rx="2.5" fill="currentColor" fillOpacity="0.18" stroke="currentColor" strokeWidth="1.4" />
          <circle cx="-2" cy="-6" r="1" fill="currentColor" />
          <circle cx="3" cy="-6" r="1" fill="currentColor" />
          <path d="M-3 -2 q3 2 6 0" stroke="currentColor" strokeWidth="1" fill="none" />
        </g>
      </g>
    </svg>);
}

const ART_MAP = {
  ota: ArtOTA,
  fintech: ArtFintech,
  live: ArtLive,
  game: ArtGame,
};

function WorkArt({ kind }) {
  const Comp = ART_MAP[kind];
  if (!Comp) return null;
  return (
    <div className={`work-art work-art-${kind}`}>
      <Comp />
    </div>);
}

window.WorkArt = WorkArt;
