// components.tsx — small reusable React bits

const { useState, useEffect, useRef, useMemo, useCallback } = (window as any).React;

function EOOnionLogo({ size = 32 }: { size?: number }) {
  return (
    <svg width={size} height={size} viewBox="0 0 64 64" aria-label="European Onion">
      <defs>
        <radialGradient id={`onbg${size}`} cx="50%" cy="55%" r="55%">
          <stop offset="0%" stopColor="#1a4fb8"/>
          <stop offset="60%" stopColor="#003399"/>
          <stop offset="100%" stopColor="#001f5c"/>
        </radialGradient>
      </defs>
      <path d="M32 8 C 30 8 28 10 28 13 C 28 14 28.5 15 29 15.5 C 22 17 14 24 14 36 C 14 48 22 58 32 58 C 42 58 50 48 50 36 C 50 24 42 17 35 15.5 C 35.5 15 36 14 36 13 C 36 10 34 8 32 8 Z" fill={`url(#onbg${size})`} stroke="#001f5c" strokeWidth="0.8"/>
      <path d="M19 30 Q 32 22 45 30" fill="none" stroke="#0050d0" strokeWidth="0.6" opacity="0.6"/>
      <path d="M17 38 Q 32 28 47 38" fill="none" stroke="#0050d0" strokeWidth="0.6" opacity="0.5"/>
      <path d="M16 46 Q 32 36 48 46" fill="none" stroke="#0050d0" strokeWidth="0.6" opacity="0.4"/>
      <path d="M32 8 C 30 6 28 4 30 2" fill="none" stroke="#1f6b3a" strokeWidth="1.4" strokeLinecap="round"/>
      <path d="M32 8 C 34 6 36 4 34 2" fill="none" stroke="#2a8a4d" strokeWidth="1.4" strokeLinecap="round"/>
      <ellipse cx="26" cy="26" rx="5" ry="9" fill="white" opacity="0.18"/>
      <g fill="#ffcc00">
        <polygon points="32,20 32.7,22 34.7,22 33.1,23.3 33.7,25.3 32,24 30.3,25.3 30.9,23.3 29.3,22 31.3,22"/>
        <polygon points="40,28 40.5,29.4 42,29.4 40.8,30.3 41.3,31.7 40,30.8 38.7,31.7 39.2,30.3 38,29.4 39.5,29.4"/>
        <polygon points="24,28 24.5,29.4 26,29.4 24.8,30.3 25.3,31.7 24,30.8 22.7,31.7 23.2,30.3 22,29.4 23.5,29.4"/>
        <polygon points="42,38 42.5,39.4 44,39.4 42.8,40.3 43.3,41.7 42,40.8 40.7,41.7 41.2,40.3 40,39.4 41.5,39.4"/>
        <polygon points="22,38 22.5,39.4 24,39.4 22.8,40.3 23.3,41.7 22,40.8 20.7,41.7 21.2,40.3 20,39.4 21.5,39.4"/>
        <polygon points="32,46 32.5,47.4 34,47.4 32.8,48.3 33.3,49.7 32,48.8 30.7,49.7 31.2,48.3 30,47.4 31.5,47.4"/>
      </g>
    </svg>
  );
}

function EOFlag({ width = 28, height = 19 }: { width?: number; height?: number }) {
  return (
    <svg width={width} height={height} viewBox="0 0 90 60">
      <rect width="90" height="60" fill="#003399"/>
      <g transform="translate(45,32)">
        <path d="M0 -10 C -1 -10 -2 -9 -2 -8 C -7 -7 -10 -3 -10 3 C -10 9 -5 14 0 14 C 5 14 10 9 10 3 C 10 -3 7 -7 2 -8 C 2 -9 1 -10 0 -10 Z" fill="#1a4fb8"/>
      </g>
      <g fill="#ffcc00">
        {Array.from({ length: 12 }).map((_, i) => {
          const angle = (i * 30) * Math.PI / 180;
          const cx = 45 + Math.cos(angle - Math.PI / 2) * 22;
          const cy = 32 + Math.sin(angle - Math.PI / 2) * 22;
          return <circle key={i} cx={cx} cy={cy} r="1.4"/>;
        })}
      </g>
    </svg>
  );
}

function CountryFlag({ code, size = 18 }: { code: string; size?: number }) {
  // Simple fallback: render the country code in a styled box
  return (
    <span
      style={{
        display: 'inline-flex',
        alignItems: 'center',
        justifyContent: 'center',
        width: size + 6,
        height: size,
        background: '#f0f0f0',
        border: '1px solid #ccc',
        borderRadius: 2,
        fontSize: 9,
        fontWeight: 700,
        fontFamily: 'monospace',
        color: '#333',
        letterSpacing: 0,
      }}
    >
      {code}
    </span>
  );
}

function JeanClaudeAvatar({ size = 36 }: { size?: number }) {
  return (
    <span
      style={{
        width: size,
        height: size,
        borderRadius: '50%',
        background: '#003399',
        display: 'inline-flex',
        alignItems: 'center',
        justifyContent: 'center',
        flexShrink: 0,
        border: '1px solid #001f5c',
      }}
    >
      <EOOnionLogo size={Math.round(size * 0.7)}/>
    </span>
  );
}

// Mascot — Ursula-the-bureaucrat (Compliance Is Our Jam grandma)
function ComplianceMascot({ width = 90 }: { width?: number }) {
  return (
    <svg viewBox="0 0 200 220" width={width} aria-label="Compliance grandma">
      {/* Background subtle */}
      <ellipse cx="100" cy="200" rx="70" ry="8" fill="#000" opacity="0.08"/>
      {/* Body coat (EU blue) */}
      <path d="M50 200 L50 130 Q50 110 65 105 L80 100 L120 100 L135 105 Q150 110 150 130 L150 200 Z" fill="#003399"/>
      {/* Coat lapels */}
      <path d="M80 100 L100 130 L120 100 L100 105 Z" fill="#001f5c"/>
      {/* Compliance brooch (stars) */}
      <circle cx="115" cy="140" r="9" fill="#ffcc00"/>
      <text x="115" y="143" fontSize="10" textAnchor="middle" fill="#003399" fontWeight="700">EO</text>
      {/* Neck */}
      <rect x="92" y="85" width="16" height="20" fill="#f0c8a8"/>
      {/* Head */}
      <ellipse cx="100" cy="70" rx="32" ry="36" fill="#f5d4b3"/>
      {/* Hair (short, gray) */}
      <path d="M68 60 Q70 38 100 35 Q130 38 132 60 Q132 50 125 45 Q115 38 100 38 Q85 38 75 45 Q68 50 68 60 Z" fill="#8a8a8a"/>
      <path d="M68 65 Q72 55 85 56 L75 68 Z" fill="#8a8a8a"/>
      <path d="M132 65 Q128 55 115 56 L125 68 Z" fill="#8a8a8a"/>
      {/* Beret (EU yellow) */}
      <ellipse cx="100" cy="35" rx="28" ry="10" fill="#ffcc00"/>
      <ellipse cx="100" cy="33" rx="26" ry="6" fill="#f5b800"/>
      <circle cx="115" cy="29" r="3" fill="#003399"/>
      {/* Glasses */}
      <circle cx="86" cy="70" r="8" fill="white" stroke="#333" strokeWidth="1.5"/>
      <circle cx="114" cy="70" r="8" fill="white" stroke="#333" strokeWidth="1.5"/>
      <line x1="94" y1="70" x2="106" y2="70" stroke="#333" strokeWidth="1.5"/>
      <circle cx="86" cy="70" r="2" fill="#1a1a1a"/>
      <circle cx="114" cy="70" r="2" fill="#1a1a1a"/>
      {/* Mouth (slight pursed smile) */}
      <path d="M92 88 Q100 92 108 88" fill="none" stroke="#a04040" strokeWidth="1.5" strokeLinecap="round"/>
      {/* Earrings */}
      <circle cx="68" cy="78" r="2" fill="#ffcc00"/>
      <circle cx="132" cy="78" r="2" fill="#ffcc00"/>
      {/* Clipboard arms */}
      <path d="M50 130 L40 160 L55 165 L60 140 Z" fill="#003399"/>
      <path d="M150 130 L160 160 L145 165 L140 140 Z" fill="#003399"/>
      {/* Hands holding clipboard */}
      <ellipse cx="50" cy="167" rx="8" ry="6" fill="#f0c8a8"/>
      <ellipse cx="150" cy="167" rx="8" ry="6" fill="#f0c8a8"/>
      {/* Clipboard */}
      <rect x="48" y="155" width="104" height="50" rx="3" fill="#f7f5ee" stroke="#333" strokeWidth="1.5"/>
      <rect x="85" y="150" width="30" height="10" rx="2" fill="#888"/>
      <text x="100" y="172" fontSize="9" textAnchor="middle" fill="#c8202c" fontWeight="700">COMPLIANCE</text>
      <text x="100" y="184" fontSize="9" textAnchor="middle" fill="#c8202c" fontWeight="700">IS OUR JAM</text>
      <line x1="58" y1="195" x2="142" y2="195" stroke="#ccc" strokeWidth="0.5"/>
      <line x1="58" y1="200" x2="142" y2="200" stroke="#ccc" strokeWidth="0.5"/>
    </svg>
  );
}

function VonDerAvatar({ size = 36 }: { size?: number }) {
  // A small institutional bust: gray hair, blazer, podium
  return (
    <svg viewBox="0 0 64 64" width={size} height={size} style={{ borderRadius: '50%', background: '#003399' }}>
      <circle cx="32" cy="32" r="32" fill="#003399"/>
      <ellipse cx="32" cy="64" rx="22" ry="14" fill="#001f5c"/>
      {/* head */}
      <ellipse cx="32" cy="28" rx="13" ry="14" fill="#f5d4b3"/>
      {/* hair */}
      <path d="M19 25 Q20 14 32 13 Q44 14 45 25 Q43 22 32 22 Q21 22 19 25 Z" fill="#a8a8a8"/>
      {/* glasses */}
      <circle cx="27" cy="29" r="3" fill="none" stroke="#222" strokeWidth="0.8"/>
      <circle cx="37" cy="29" r="3" fill="none" stroke="#222" strokeWidth="0.8"/>
      <line x1="30" y1="29" x2="34" y2="29" stroke="#222" strokeWidth="0.8"/>
      {/* mouth */}
      <path d="M28 35 Q32 37 36 35" fill="none" stroke="#a04040" strokeWidth="1" strokeLinecap="round"/>
      {/* suit */}
      <path d="M14 56 Q14 46 24 44 L40 44 Q50 46 50 56 Z" fill="#001f5c"/>
      <rect x="30" y="44" width="4" height="14" fill="#ffcc00"/>
    </svg>
  );
}

(window as any).Components = {
  EOOnionLogo, EOFlag, CountryFlag, JeanClaudeAvatar, VonDerAvatar, ComplianceMascot,
};
