// flags.jsx — simple flat SVG flags, desaturated to sit with the blues
// Drawn at 3:2, styled to 28×18 at size=28 (or 36×24 at size=36).
// Intentionally simplified — per Traduality guidance: clean flat flags, not emoji.

const FLAG_SVGS = {
  // Mexico — simplified: vertical green/white/red
  mx: (
    <g>
      <rect width="12" height="20" x="0"  fill="#006847"/>
      <rect width="12" height="20" x="12" fill="#fff"/>
      <rect width="12" height="20" x="24" fill="#ce1126"/>
      <circle cx="18" cy="10" r="3" fill="none" stroke="#8a6d3b" strokeWidth="0.6"/>
    </g>
  ),
  // China — red w/ yellow stars (simplified to one large star)
  cn: (
    <g>
      <rect width="36" height="20" fill="#de2910"/>
      <polygon points="7,4 8.5,7.5 12,7.8 9.3,10 10.1,13.5 7,11.5 3.9,13.5 4.7,10 2,7.8 5.5,7.5" fill="#ffde00"/>
      <circle cx="13" cy="3.5" r="0.9" fill="#ffde00"/>
      <circle cx="14.5" cy="5.5" r="0.9" fill="#ffde00"/>
      <circle cx="14.5" cy="8.5" r="0.9" fill="#ffde00"/>
      <circle cx="13" cy="10.5" r="0.9" fill="#ffde00"/>
    </g>
  ),
  // Vietnam — red w/ yellow star
  vn: (
    <g>
      <rect width="36" height="20" fill="#da251d"/>
      <polygon points="18,4 19.8,9 25,9 21,12.2 22.6,17.2 18,14.2 13.4,17.2 15,12.2 11,9 16.2,9" fill="#ffde00"/>
    </g>
  ),
  // South Korea — white w/ taegeuk + simplified trigrams
  kr: (
    <g>
      <rect width="36" height="20" fill="#fff"/>
      <circle cx="18" cy="10" r="4.2" fill="#c60c30"/>
      <path d="M13.8 10 a4.2 4.2 0 0 1 8.4 0 a2.1 2.1 0 0 1 -4.2 0 a2.1 2.1 0 0 0 -4.2 0 z" fill="#003478"/>
      <g fill="#000">
        <rect x="5" y="4" width="4" height="0.8"/><rect x="5" y="5.5" width="4" height="0.8"/><rect x="5" y="7" width="4" height="0.8"/>
        <rect x="27" y="4" width="4" height="0.8"/><rect x="27" y="5.5" width="1.6" height="0.8"/><rect x="29.4" y="5.5" width="1.6" height="0.8"/><rect x="27" y="7" width="4" height="0.8"/>
        <rect x="5" y="13" width="4" height="0.8"/><rect x="5" y="14.5" width="4" height="0.8"/><rect x="5" y="16" width="1.6" height="0.8"/><rect x="7.4" y="16" width="1.6" height="0.8"/>
        <rect x="27" y="13" width="1.6" height="0.8"/><rect x="29.4" y="13" width="1.6" height="0.8"/><rect x="27" y="14.5" width="4" height="0.8"/><rect x="27" y="16" width="1.6" height="0.8"/><rect x="29.4" y="16" width="1.6" height="0.8"/>
      </g>
    </g>
  ),
  // Haiti — blue/red horizontal
  ht: (
    <g>
      <rect width="36" height="10" fill="#00209f"/>
      <rect width="36" height="10" y="10" fill="#d21034"/>
      <rect x="14.5" y="7" width="7" height="6" fill="#fff"/>
    </g>
  ),
  // Saudi Arabia (for Arabic) — green with simplified calligraphy bar + sword
  sa: (
    <g>
      <rect width="36" height="20" fill="#006c35"/>
      <rect x="6" y="6" width="24" height="1.4" fill="#fff"/>
      <rect x="6" y="12" width="24" height="0.7" fill="#fff"/>
      <polygon points="6,12 29,12 28,13 7,13" fill="#fff"/>
    </g>
  ),
  // France — vertical blue/white/red
  fr: (
    <g>
      <rect width="12" height="20" x="0"  fill="#002395"/>
      <rect width="12" height="20" x="12" fill="#fff"/>
      <rect width="12" height="20" x="24" fill="#ed2939"/>
    </g>
  ),
  // Brazil (for Portuguese) — green w/ yellow diamond + blue circle
  br: (
    <g>
      <rect width="36" height="20" fill="#009c3b"/>
      <polygon points="18,3 32,10 18,17 4,10" fill="#ffdf00"/>
      <circle cx="18" cy="10" r="3.8" fill="#002776"/>
      <path d="M14.3 10 q3.7 -2.4 7.4 0" fill="none" stroke="#fff" strokeWidth="0.6"/>
    </g>
  ),
  // Russia — white/blue/red horizontal
  ru: (
    <g>
      <rect width="36" height="6.67" y="0" fill="#fff"/>
      <rect width="36" height="6.67" y="6.67" fill="#0039a6"/>
      <rect width="36" height="6.67" y="13.33" fill="#d52b1e"/>
    </g>
  ),
  // India — horizontal saffron/white/green + wheel
  in: (
    <g>
      <rect width="36" height="6.67" y="0" fill="#ff9933"/>
      <rect width="36" height="6.67" y="6.67" fill="#fff"/>
      <rect width="36" height="6.67" y="13.33" fill="#138808"/>
      <circle cx="18" cy="10" r="2.5" fill="none" stroke="#000080" strokeWidth="0.5"/>
      <circle cx="18" cy="10" r="0.5" fill="#000080"/>
    </g>
  ),
  // Philippines — horizontal blue/red with white triangle
  ph: (
    <g>
      <rect width="36" height="10" fill="#0038a8"/>
      <rect width="36" height="10" y="10" fill="#ce1126"/>
      <polygon points="0,0 0,20 15,10" fill="#fff"/>
      <circle cx="4.5" cy="10" r="1.4" fill="#fcd116"/>
    </g>
  ),
  // Kenya (for Swahili) — black/red/green w/ shield
  ke: (
    <g>
      <rect width="36" height="6" y="0" fill="#000"/>
      <rect width="36" height="1" y="6" fill="#fff"/>
      <rect width="36" height="6" y="7" fill="#bb0000"/>
      <rect width="36" height="1" y="13" fill="#fff"/>
      <rect width="36" height="6" y="14" fill="#006600"/>
      <ellipse cx="18" cy="10" rx="2.8" ry="4.2" fill="#bb0000" stroke="#fff" strokeWidth="0.6"/>
    </g>
  ),
};

function Flag({ code, size = 28, style = {} }) {
  const g = FLAG_SVGS[code];
  if (!g) return null;
  const w = size;
  const h = Math.round(size * 20 / 36);
  return (
    <svg
      width={w} height={h} viewBox="0 0 36 20"
      style={{
        display: 'block',
        borderRadius: 3,
        boxShadow: '0 0 0 1px rgba(15,56,92,0.12), 0 1px 2px rgba(15,56,92,0.08)',
        filter: 'saturate(0.88)',
        flexShrink: 0,
        ...style,
      }}
    >
      {g}
    </svg>
  );
}

Object.assign(window, { Flag });
