﻿/* icons.jsx - inline icons, simple flags, and radar chart */
function Flag({ team, ...p }) {
  const common = { viewBox: "0 0 60 40", preserveAspectRatio: "none", ...p };
  const map = {
    ned: <svg {...common}><rect width="60" height="13.33" fill="#AE1C28"/><rect y="13.33" width="60" height="13.33" fill="#fff"/><rect y="26.66" width="60" height="13.34" fill="#21468B"/></svg>,
    jpn: <svg {...common}><rect width="60" height="40" fill="#fff"/><circle cx="30" cy="20" r="9.5" fill="#BC002D"/></svg>,
    swe: <svg {...common}><rect width="60" height="40" fill="#006AA7"/><rect x="18" width="7" height="40" fill="#FECC00"/><rect y="16.5" width="60" height="7" fill="#FECC00"/></svg>,
    tun: <svg {...common}><rect width="60" height="40" fill="#E70013"/><circle cx="30" cy="20" r="11" fill="#fff"/><circle cx="33" cy="20" r="7.8" fill="#E70013"/><circle cx="35" cy="20" r="6" fill="#fff"/></svg>
  };
  return map[team] || null;
}

function BallMark({ size = 22, color = "currentColor" }) {
  return <svg width={size} height={size} viewBox="0 0 24 24" fill="none" aria-hidden="true"><circle cx="12" cy="12" r="9.2" stroke={color} strokeWidth="1.6"/><path d="M12 7l3.4 2.5-1.3 4H9.9l-1.3-4L12 7z" fill={color}/><path d="M12 7V3.2M15.4 9.5l3.4-1.2M14.1 13.5l2.4 3M9.9 13.5l-2.4 3M8.6 9.5L5.2 8.3" stroke={color} strokeWidth="1.4" strokeLinecap="round"/></svg>;
}

const I = {
  arrow: <svg viewBox="0 0 24 24" fill="none" aria-hidden="true"><path d="M5 12h14M13 6l6 6-6 6" stroke="currentColor" strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round"/></svg>,
  tv: <svg viewBox="0 0 24 24" fill="none" aria-hidden="true"><rect x="3" y="5" width="18" height="12" rx="2" stroke="currentColor" strokeWidth="1.8"/><path d="M8 21h8M12 17v4" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round"/></svg>,
  cast: <svg viewBox="0 0 24 24" fill="none" aria-hidden="true"><path d="M3 16a5 5 0 0 1 5 5M3 12a9 9 0 0 1 9 9M3 8a13 13 0 0 1 13 13" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round"/><rect x="3" y="4" width="18" height="13" rx="2" stroke="currentColor" strokeWidth="1.8" opacity=".45"/></svg>,
  device: <svg viewBox="0 0 24 24" fill="none" aria-hidden="true"><rect x="3" y="6" width="13" height="9" rx="1.5" stroke="currentColor" strokeWidth="1.8"/><rect x="17" y="9" width="4" height="11" rx="1" stroke="currentColor" strokeWidth="1.8"/></svg>,
  hdmi: <svg viewBox="0 0 24 24" fill="none" aria-hidden="true"><path d="M4 9h16v4l-2 3H6l-2-3V9z" stroke="currentColor" strokeWidth="1.8" strokeLinejoin="round"/><path d="M8 9V7h8v2" stroke="currentColor" strokeWidth="1.8"/></svg>,
  audio: <svg viewBox="0 0 24 24" fill="none" aria-hidden="true"><path d="M11 5L6 9H3v6h3l5 4V5z" stroke="currentColor" strokeWidth="1.8" strokeLinejoin="round"/><path d="M15 9a4 4 0 0 1 0 6M18 6a8 8 0 0 1 0 12" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round"/></svg>,
  flag: <svg viewBox="0 0 24 24" fill="none" aria-hidden="true"><path d="M5 21V4M5 4h12l-2 4 2 4H5" stroke="currentColor" strokeWidth="1.8" strokeLinejoin="round"/></svg>,
  moon: <svg viewBox="0 0 24 24" fill="none" aria-hidden="true"><path d="M20 15.2A8.2 8.2 0 0 1 8.8 4a7 7 0 1 0 11.2 11.2z" stroke="currentColor" strokeWidth="1.8" strokeLinejoin="round"/></svg>,
  info: <svg viewBox="0 0 24 24" fill="none" aria-hidden="true"><circle cx="12" cy="12" r="9" stroke="currentColor" strokeWidth="1.8"/><path d="M12 11v5M12 8h.01" stroke="currentColor" strokeWidth="2" strokeLinecap="round"/></svg>,
  play: <svg viewBox="0 0 24 24" fill="none" aria-hidden="true"><circle cx="12" cy="12" r="10" fill="currentColor" opacity=".16"/><path d="M10 8.2l6.3 3.8-6.3 3.8V8.2z" fill="currentColor"/></svg>
};

function HexRadar({ axes, series, size = 320, max = 100, labels = true }) {
  const cx = size / 2;
  const cy = size / 2;
  const n = axes.length;
  const radius = size * (labels ? 0.31 : 0.39);
  const angle = (i) => Math.PI * 2 * i / n - Math.PI / 2;
  const point = (i, r) => [cx + Math.cos(angle(i)) * r, cy + Math.sin(angle(i)) * r];
  const poly = (factor) => axes.map((_, i) => point(i, radius * factor).join(",")).join(" ");
  return (
    <svg viewBox={`0 0 ${size} ${size}`} className="radar" role="img" aria-label="6軸レーダーチャート">
      {[0.25, 0.5, 0.75, 1].map((f, i) => <polygon key={f} points={poly(f)} fill="none" stroke="currentColor" strokeOpacity={i === 3 ? ".38" : ".2"} strokeWidth="1" />)}
      {axes.map((_, i) => { const [x, y] = point(i, radius); return <line key={i} x1={cx} y1={cy} x2={x} y2={y} stroke="currentColor" strokeOpacity=".18" strokeWidth="1"/>; })}
      {series.map((s, si) => {
        const points = s.values.map((v, i) => point(i, radius * Math.max(0, Math.min(v, max)) / max).join(",")).join(" ");
        return <g key={si}><polygon points={points} fill={s.color} fillOpacity={s.fill ?? .2} stroke={s.color} strokeWidth="2.7" strokeLinejoin="round" />{s.values.map((v, i) => { const [x, y] = point(i, radius * v / max); return <circle key={i} cx={x} cy={y} r="3.2" fill={s.color} stroke="#fff" strokeWidth="1.2"/>; })}</g>;
      })}
      {labels && axes.map((label, i) => {
        const [x, y] = point(i, radius + 32);
        const anchor = Math.abs(x - cx) < 10 ? "middle" : x > cx ? "start" : "end";
        return <text key={label} x={x} y={y + 4} textAnchor={anchor} className="radar__axis-label" fill="#F8FAFC" stroke="rgba(0,0,0,.65)" paintOrder="stroke" style={{ textShadow: "0 1px 6px rgba(0,0,0,.75)" }}>{label}</text>;
      })}
    </svg>
  );
}

Object.assign(window, { Flag, BallMark, I, HexRadar });



