/* Icons + small SVG components — shared across pages */
const Icon = {
  arrow: (p={}) => <svg viewBox="0 0 24 24" width={p.size||14} height={p.size||14} fill="none" stroke="currentColor" strokeWidth="2" {...p}><path d="M5 12h14M13 6l6 6-6 6" /></svg>,
  arrowDown: (p={}) => <svg viewBox="0 0 24 24" width={p.size||10} height={p.size||10} fill="none" stroke="currentColor" strokeWidth="2.5" {...p}><path d="M6 9l6 6 6-6" /></svg>,
  external: (p={}) => <svg viewBox="0 0 24 24" width={p.size||12} height={p.size||12} fill="none" stroke="currentColor" strokeWidth="2" {...p}><path d="M14 4h6v6M20 4l-9 9M9 4H6a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-3" /></svg>,
  search: (p={}) => <svg viewBox="0 0 24 24" width={p.size||16} height={p.size||16} fill="none" stroke="currentColor" strokeWidth="2" {...p}><circle cx="11" cy="11" r="7"/><path d="M21 21l-4.3-4.3"/></svg>,
  plus: (p={}) => <svg viewBox="0 0 24 24" width={p.size||16} height={p.size||16} fill="none" stroke="currentColor" strokeWidth="2.5" {...p}><path d="M12 5v14M5 12h14"/></svg>,
  trophy: (p={}) => <svg viewBox="0 0 24 24" width={p.size||44} height={p.size||44} fill="none" stroke="currentColor" strokeWidth="1.6" {...p}><path d="M8 21h8M12 17v4M7 4h10v4a5 5 0 0 1-10 0V4z"/><path d="M17 4h3v3a3 3 0 0 1-3 3M7 4H4v3a3 3 0 0 0 3 3"/></svg>,
  twitch: (p={}) => <svg viewBox="0 0 24 24" width={p.size||14} height={p.size||14} fill="currentColor" {...p}><path d="M4 2v18h5v3l3-3h4l5-5V2H4zm16 11l-3 3h-4l-3 3v-3H7V4h13v9zM18 6h-2v6h2V6zm-5 0h-2v6h2V6z"/></svg>,
  youtube: (p={}) => <svg viewBox="0 0 24 24" width={p.size||14} height={p.size||14} fill="currentColor" {...p}><path d="M22 7.5a2.5 2.5 0 0 0-1.8-1.8C18.6 5.3 12 5.3 12 5.3s-6.6 0-8.2.4A2.5 2.5 0 0 0 2 7.5C1.6 9.1 1.6 12 1.6 12s0 2.9.4 4.5A2.5 2.5 0 0 0 3.8 18.3C5.4 18.7 12 18.7 12 18.7s6.6 0 8.2-.4A2.5 2.5 0 0 0 22 16.5c.4-1.6.4-4.5.4-4.5s0-2.9-.4-4.5zM10 15V9l5.2 3L10 15z"/></svg>,
  discord: (p={}) => <svg viewBox="0 0 24 24" width={p.size||14} height={p.size||14} fill="currentColor" {...p}><path d="M19.3 5.3A17 17 0 0 0 15 4l-.2.4a14 14 0 0 1 4 2c-2-1-4-1.6-6.8-1.6-2.7 0-4.7.6-6.7 1.6a14 14 0 0 1 4-2L9.1 4a17 17 0 0 0-4.4 1.3C2 9.5 1.4 13.6 1.7 17.6c1.7 1.3 3.5 2.1 5.2 2.6.4-.5.8-1.1 1-1.7-.6-.2-1.2-.5-1.8-.9.2-.1.3-.2.5-.3 3.5 1.6 7.3 1.6 10.8 0 .2.1.3.2.5.3-.6.4-1.2.6-1.8.9.3.6.6 1.2 1 1.7 1.7-.5 3.5-1.3 5.2-2.6.4-4.6-.6-8.6-3-12.3zM8.5 15c-1 0-1.9-1-1.9-2.1S7.4 11 8.5 11s1.9 1 1.9 2 -.9 2-1.9 2zm6.9 0c-1 0-1.9-1-1.9-2.1S14.5 11 15.5 11s1.9 1 1.9 2-.9 2-1.9 2z"/></svg>,
  x: (p={}) => <svg viewBox="0 0 24 24" width={p.size||13} height={p.size||13} fill="currentColor" {...p}><path d="M17 3h3l-7 8 8 10h-6l-5-6-5 6H2l8-9-8-9h6l4 5 5-5z"/></svg>,
  instagram: (p={}) => <svg viewBox="0 0 24 24" width={p.size||14} height={p.size||14} fill="none" stroke="currentColor" strokeWidth="1.8" {...p}><rect x="3" y="3" width="18" height="18" rx="4"/><circle cx="12" cy="12" r="4"/><circle cx="17.5" cy="6.5" r="0.8" fill="currentColor"/></svg>,
};

window.Icon = Icon;

/* Official LoL position icons — recreated to match Riot's minimap-corner stylisation.
   TOP: solid corner block in top-left + diagonal "river" line
   JUNGLE: stylised leaf
   MID: diagonal river line crossing the map
   ADC (BOTTOM): solid corner block in bottom-right + diagonal river line
   SUPPORT (UTILITY): stylised shield with cross
*/
const ROLE_ICON_MAP = {
  TOP: ({ size = 20 }) => (
    <svg viewBox="0 0 100 100" width={size} height={size} fill="currentColor">
      <path d="M2 2 H46 V18 H18 V46 H2 Z"/>
      <path d="M14 86 L86 14 L92 20 L20 92 Z" opacity="0.55"/>
    </svg>
  ),
  JUNGLE: ({ size = 20 }) => (
    <svg viewBox="0 0 100 100" width={size} height={size} fill="currentColor">
      <path d="M50 6 C 22 22 12 50 22 78 C 40 70 56 56 64 38 C 58 56 50 70 32 84 C 60 90 86 72 92 44 C 80 50 68 52 58 50 C 76 44 88 30 92 12 C 78 18 64 22 50 26 Z"/>
    </svg>
  ),
  MID: ({ size = 20 }) => (
    <svg viewBox="0 0 100 100" width={size} height={size} fill="currentColor">
      <rect x="2" y="2" width="22" height="22" />
      <rect x="76" y="76" width="22" height="22" />
      <path d="M14 86 L86 14 L92 20 L20 92 Z" opacity="0.7"/>
    </svg>
  ),
  ADC: ({ size = 20 }) => (
    <svg viewBox="0 0 100 100" width={size} height={size} fill="currentColor">
      <path d="M98 98 H54 V82 H82 V54 H98 Z"/>
      <path d="M14 86 L86 14 L92 20 L20 92 Z" opacity="0.55"/>
    </svg>
  ),
  SUPPORT: ({ size = 20 }) => (
    <svg viewBox="0 0 100 100" width={size} height={size} fill="currentColor">
      <path d="M50 6 L88 22 V52 C 88 74 72 88 50 96 C 28 88 12 74 12 52 V22 Z" />
      <path d="M44 30 H56 V46 H72 V58 H56 V78 H44 V58 H28 V46 H44 Z" fill="#0c1428"/>
    </svg>
  ),
  GENERIC: ({ size = 20 }) => (
    <svg viewBox="0 0 100 100" width={size} height={size} fill="none" stroke="currentColor" strokeWidth="6">
      <circle cx="50" cy="50" r="42"/>
      <circle cx="50" cy="50" r="14" fill="currentColor" stroke="none"/>
    </svg>
  ),
};
window.RoleIcon = function RoleIcon({ role, size = 20 }) {
  const C = ROLE_ICON_MAP[role] || ROLE_ICON_MAP.GENERIC;
  return <C size={size} />;
};

// Brand mark — official Abyssalis logo
window.BrandMark = function BrandMark({ size = 36 }) {
  return (
    <img src="assets/logo.ico" alt="Abyssalis Esports" width={size} height={size}
      style={{ display: "block", objectFit: "contain", filter: "drop-shadow(0 0 12px rgba(77,168,255,0.35))" }}
    />
  );
};

// Game glyph (simple stylised mark per game)
window.GameGlyph = function GameGlyph({ id, color = "#4DA8FF" }) {
  switch (id) {
    case "lol":
      return <svg viewBox="0 0 200 200" style={{width:"100%",height:"100%"}}><path d="M30 30 L60 30 L60 150 L150 150 L150 180 L30 180 Z" fill={color}/><path d="M100 50 L130 50 L130 130 L100 130 Z" fill={color}/></svg>;
    case "val":
      return <svg viewBox="0 0 200 200" style={{width:"100%",height:"100%"}}><path d="M20 30 L60 30 L100 130 L140 30 L180 30 L120 170 L80 170 Z" fill={color}/></svg>;
    case "cs2":
      return <svg viewBox="0 0 200 200" style={{width:"100%",height:"100%"}}><circle cx="100" cy="100" r="60" fill="none" stroke={color} strokeWidth="22"/><path d="M40 100 H160 M100 40 V160" stroke={color} strokeWidth="6"/></svg>;
    case "rl":
      return <svg viewBox="0 0 200 200" style={{width:"100%",height:"100%"}}><circle cx="100" cy="100" r="65" fill="none" stroke={color} strokeWidth="10"/><path d="M55 80 L100 50 L145 80 L145 130 L100 160 L55 130 Z" fill="none" stroke={color} strokeWidth="6"/></svg>;
    case "tft":
      return <svg viewBox="0 0 200 200" style={{width:"100%",height:"100%"}}><path d="M40 60 L100 30 L160 60 L160 130 L100 170 L40 130 Z" fill="none" stroke={color} strokeWidth="8"/><circle cx="100" cy="100" r="22" fill={color}/></svg>;
    default: return null;
  }
};

// Team logo placeholder — uses team abbr inside a slanted shape
window.TeamLogo = function TeamLogo({ team, size = 80 }) {
  const palette = {
    "abyssalis-lol": ["#4DA8FF", "#0a3a55"],
    "abyssalis-vlr": ["#FF4655", "#3a1a2e"],
    "abyssalis-cs2": ["#F4C75B", "#2a2410"],
    "abyssalis-rl":  ["#7BC4FF", "#0a2545"],
    "abyssalis-tft": ["#A78BFA", "#15213d"],
  };
  const [accent, bg] = palette[team.slug] || ["#4DA8FF", "#0a3a55"];
  return (
    <svg viewBox="0 0 80 80" width={size} height={size} style={{display:"block"}}>
      <defs>
        <linearGradient id={`lg-${team.slug}`} x1="0" y1="0" x2="0" y2="1">
          <stop offset="0" stopColor={accent} stopOpacity="0.32"/>
          <stop offset="1" stopColor={bg} stopOpacity="0.7"/>
        </linearGradient>
      </defs>
      <rect width="80" height="80" fill={`url(#lg-${team.slug})`}/>
      {/* abyss waves */}
      <path d="M0 60 Q20 52 40 60 T80 60 V80 H0 Z" fill={accent} opacity="0.18"/>
      <path d="M0 68 Q20 62 40 68 T80 68 V80 H0 Z" fill={accent} opacity="0.12"/>
      {/* abbr */}
      <text x="40" y="42" textAnchor="middle" fontFamily="'Big Shoulders Display', sans-serif" fontWeight="900" fontSize="26" fill={accent} letterSpacing="2">
        {team.abbr}
      </text>
      <text x="40" y="58" textAnchor="middle" fontFamily="'JetBrains Mono', monospace" fontWeight="500" fontSize="6.5" fill="#F4F8FF" opacity="0.55" letterSpacing="2">
        EST {team.founded}
      </text>
    </svg>
  );
};

// Sponsor logo — typographic placeholder
window.SponsorLogo = function SponsorLogo({ name }) {
  return (
    <span style={{ fontFamily: "var(--display)", fontWeight: 800, letterSpacing: "0.04em" }}>
      {name.toUpperCase()}
    </span>
  );
};
