// SVG illustration set — mahjong tile compositions used as hero/card art.

const TileFace = ({ symbol, color = "#0F6E3D", small }) => (
  <g>
    <rect x="0" y="0" width="60" height="84" rx="6" fill="#fff8ec" />
    <rect x="0" y="0" width="60" height="84" rx="6" fill="none" stroke="#d9c79a" strokeWidth="1.2" />
    <rect x="3" y="3" width="54" height="78" rx="4" fill="none" stroke="#eadeb6" strokeWidth="0.8" />
    {symbol === "1man" && (
      <g>
        <text x="30" y="38" textAnchor="middle" fontSize="24" fontFamily="serif" fontWeight="700" fill={color}>一</text>
        <text x="30" y="68" textAnchor="middle" fontSize="22" fontFamily="serif" fontWeight="700" fill="#a72a1a">萬</text>
      </g>
    )}
    {symbol === "9man" && (
      <g>
        <text x="30" y="38" textAnchor="middle" fontSize="22" fontFamily="serif" fontWeight="700" fill={color}>九</text>
        <text x="30" y="68" textAnchor="middle" fontSize="22" fontFamily="serif" fontWeight="700" fill="#a72a1a">萬</text>
      </g>
    )}
    {symbol === "chun" && (
      <text x="30" y="58" textAnchor="middle" fontSize="38" fontFamily="serif" fontWeight="700" fill="#c8102e">中</text>
    )}
    {symbol === "haku" && (
      <rect x="10" y="14" width="40" height="56" rx="2" fill="none" stroke="#0F6E3D" strokeWidth="3" />
    )}
    {symbol === "hatsu" && (
      <text x="30" y="58" textAnchor="middle" fontSize="38" fontFamily="serif" fontWeight="700" fill="#0F6E3D">發</text>
    )}
    {symbol === "ton" && (
      <text x="30" y="56" textAnchor="middle" fontSize="34" fontFamily="serif" fontWeight="700" fill="#1a1a1a">東</text>
    )}
    {symbol === "nan" && (
      <text x="30" y="56" textAnchor="middle" fontSize="34" fontFamily="serif" fontWeight="700" fill="#1a1a1a">南</text>
    )}
    {symbol === "sha" && (
      <text x="30" y="56" textAnchor="middle" fontSize="34" fontFamily="serif" fontWeight="700" fill="#1a1a1a">西</text>
    )}
    {symbol === "pei" && (
      <text x="30" y="56" textAnchor="middle" fontSize="34" fontFamily="serif" fontWeight="700" fill="#1a1a1a">北</text>
    )}
    {symbol?.endsWith("pin") && (
      <g>
        {(() => {
          const n = parseInt(symbol);
          const dots = [];
          const cfg = {
            1: [[30,42]],
            5: [[16,22],[44,22],[30,42],[16,62],[44,62]],
            9: Array.from({length:9},(_,i)=>[16+(i%3)*14,22+Math.floor(i/3)*20])
          }[n] || [];
          cfg.forEach(([cx,cy],i)=>dots.push(
            <circle key={i} cx={cx} cy={cy} r="6" fill={i%2?"#0F6E3D":"#c8102e"} stroke="#fff" strokeWidth="1.5"/>
          ));
          return dots;
        })()}
      </g>
    )}
    {symbol?.endsWith("sou") && (
      <g>
        {(() => {
          const n = parseInt(symbol);
          const items = [];
          for(let i=0;i<n;i++){
            const x = 16 + (i%3)*14;
            const y = 22 + Math.floor(i/3)*20;
            items.push(
              <g key={i}>
                <rect x={x-1.5} y={y-7} width="3" height="14" fill="#0F6E3D"/>
                <circle cx={x} cy={y-8} r="3" fill="#c8102e"/>
              </g>
            );
          }
          return items;
        })()}
      </g>
    )}
  </g>
);

// Hero illustration: a sweeping arrangement of stacked tiles
const HeroTilesArt = ({ variant = "a" }) => {
  if (variant === "a") {
    // East-style — terminal & honor showcase
    return (
      <svg viewBox="0 0 560 480" xmlns="http://www.w3.org/2000/svg">
        <defs>
          <filter id="ts1" x="-10%" y="-10%" width="120%" height="120%">
            <feGaussianBlur in="SourceAlpha" stdDeviation="6"/>
            <feOffset dx="0" dy="8"/>
            <feComponentTransfer><feFuncA type="linear" slope="0.35"/></feComponentTransfer>
            <feMerge><feMergeNode/><feMergeNode in="SourceGraphic"/></feMerge>
          </filter>
        </defs>
        <g filter="url(#ts1)">
          <g transform="translate(40,90) rotate(-8)"><TileFace symbol="chun"/></g>
          <g transform="translate(110,60) rotate(-3)"><TileFace symbol="hatsu"/></g>
          <g transform="translate(180,50) rotate(2)"><TileFace symbol="haku"/></g>
          <g transform="translate(250,60) rotate(6)"><TileFace symbol="ton"/></g>
          <g transform="translate(320,80) rotate(10)"><TileFace symbol="nan"/></g>
        </g>
        <g filter="url(#ts1)">
          <g transform="translate(70,210) rotate(-4)"><TileFace symbol="1man"/></g>
          <g transform="translate(140,200) rotate(0)"><TileFace symbol="5pin"/></g>
          <g transform="translate(210,200) rotate(2)"><TileFace symbol="9sou"/></g>
          <g transform="translate(280,210) rotate(5)"><TileFace symbol="9man"/></g>
        </g>
        <g filter="url(#ts1)" opacity="0.85">
          <g transform="translate(110,340) rotate(-2)"><TileFace symbol="sha"/></g>
          <g transform="translate(180,335) rotate(1)"><TileFace symbol="pei"/></g>
          <g transform="translate(250,340) rotate(4)"><TileFace symbol="1pin"/></g>
        </g>
      </svg>
    );
  }
  if (variant === "b") {
    // pinzu cascade with green flat backdrop tile shapes
    return (
      <svg viewBox="0 0 560 480" xmlns="http://www.w3.org/2000/svg">
        <g opacity="0.18">
          {Array.from({length:5}).map((_,i)=>(
            <rect key={i} x={40+i*70} y={40+i*30} width="80" height="120" rx="10" fill="#fff"/>
          ))}
        </g>
        <g transform="translate(120,140)">
          <g transform="rotate(-12)"><TileFace symbol="5pin"/></g>
        </g>
        <g transform="translate(220,100)">
          <g transform="rotate(-4)"><TileFace symbol="9pin"/></g>
        </g>
        <g transform="translate(320,140)">
          <g transform="rotate(6)"><TileFace symbol="1pin"/></g>
        </g>
        <g transform="translate(180,270)"><TileFace symbol="chun"/></g>
        <g transform="translate(260,260)"><TileFace symbol="hatsu"/></g>
        <g transform="translate(340,270)"><TileFace symbol="haku"/></g>
      </svg>
    );
  }
  // c — dramatic single big tile
  return (
    <svg viewBox="0 0 560 480" xmlns="http://www.w3.org/2000/svg">
      <g transform="translate(160,80) scale(3.5)">
        <TileFace symbol="chun" />
      </g>
      <g opacity="0.5">
        <g transform="translate(40,360) rotate(-10)"><TileFace symbol="hatsu"/></g>
        <g transform="translate(380,360) rotate(8)"><TileFace symbol="haku"/></g>
      </g>
    </svg>
  );
};

// Background field — for news cards & pickups
const TileField = ({ palette = "green", pattern = "scatter" }) => {
  const bg = palette === "green" ? "#0F6E3D"
           : palette === "red"   ? "#7a1424"
           : palette === "gold"  ? "#B8893A"
           : palette === "ink"   ? "#1f2937"
           : palette === "navy"  ? "#1e3a5f"
           : palette === "cream" ? "#e8dcb8"
           : "#0F6E3D";
  const fg = palette === "cream" ? "#0F6E3D" : "#fff";
  return (
    <svg viewBox="0 0 400 250" xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="xMidYMid slice"
      style={{width:"100%",height:"100%"}}>
      <rect width="400" height="250" fill={bg}/>
      <defs>
        <pattern id={`grid-${palette}`} width="40" height="40" patternUnits="userSpaceOnUse">
          <path d="M40 0 L0 0 L0 40" fill="none" stroke={fg} strokeOpacity="0.06" strokeWidth="1"/>
        </pattern>
      </defs>
      <rect width="400" height="250" fill={`url(#grid-${palette})`}/>
      {pattern === "scatter" && (
        <g opacity="0.95">
          <g transform="translate(40,60) rotate(-8) scale(0.9)"><TileFace symbol="chun"/></g>
          <g transform="translate(140,80) rotate(4) scale(0.9)"><TileFace symbol="5pin"/></g>
          <g transform="translate(240,55) rotate(-3) scale(0.9)"><TileFace symbol="9man"/></g>
          <g transform="translate(320,90) rotate(8) scale(0.9)"><TileFace symbol="hatsu"/></g>
        </g>
      )}
      {pattern === "row" && (
        <g transform="translate(20,90)" opacity="0.95">
          {["1pin","5pin","9pin","chun","hatsu"].map((s,i)=>(
            <g key={i} transform={`translate(${i*72},0) rotate(${(i-2)*2})`}><TileFace symbol={s}/></g>
          ))}
        </g>
      )}
      {pattern === "tower" && (
        <g opacity="0.95">
          <g transform="translate(150,30)"><TileFace symbol="ton"/></g>
          <g transform="translate(220,30)"><TileFace symbol="nan"/></g>
          <g transform="translate(150,130)"><TileFace symbol="sha"/></g>
          <g transform="translate(220,130)"><TileFace symbol="pei"/></g>
        </g>
      )}
      {pattern === "single" && (
        <g transform="translate(170,55) scale(1.4)"><TileFace symbol="chun"/></g>
      )}
    </svg>
  );
};

// Icons for service tiles & quicklinks
const Icon = ({ name }) => {
  const props = { fill: "none", stroke: "currentColor", strokeWidth: 1.6, strokeLinecap: "round", strokeLinejoin: "round" };
  switch (name) {
    case "trophy": return <svg viewBox="0 0 24 24" {...props}><path d="M7 4h10v4a5 5 0 0 1-10 0V4Z"/><path d="M5 5H3v2a3 3 0 0 0 3 3"/><path d="M19 5h2v2a3 3 0 0 1-3 3"/><path d="M8 19h8M10 16h4l-1 3h-2l-1-3Z"/></svg>;
    case "school": return <svg viewBox="0 0 24 24" {...props}><path d="M3 9 12 4l9 5-9 5-9-5Z"/><path d="M7 11v5l5 3 5-3v-5"/><path d="M21 9v6"/></svg>;
    case "tile": return <svg viewBox="0 0 24 24" {...props}><rect x="6" y="3" width="12" height="18" rx="2"/><path d="M9 8h6M9 12h6M9 16h6"/></svg>;
    case "play": return <svg viewBox="0 0 24 24" {...props}><circle cx="12" cy="12" r="9"/><path d="M10 8.5 16 12l-6 3.5v-7Z" fill="currentColor"/></svg>;
    case "shop": return <svg viewBox="0 0 24 24" {...props}><path d="M4 8h16l-1 11a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2L4 8Z"/><path d="M9 8V6a3 3 0 0 1 6 0v2"/></svg>;
    case "calendar": return <svg viewBox="0 0 24 24" {...props}><rect x="3" y="5" width="18" height="16" rx="2"/><path d="M8 3v4M16 3v4M3 10h18"/></svg>;
    case "users": return <svg viewBox="0 0 24 24" {...props}><circle cx="9" cy="8" r="3"/><path d="M3 20a6 6 0 0 1 12 0"/><circle cx="17" cy="9" r="2.5"/><path d="M15 14a5 5 0 0 1 6 6"/></svg>;
    case "globe": return <svg viewBox="0 0 24 24" {...props}><circle cx="12" cy="12" r="9"/><path d="M3 12h18M12 3a14 14 0 0 1 0 18M12 3a14 14 0 0 0 0 18"/></svg>;
    case "ranking": return <svg viewBox="0 0 24 24" {...props}><path d="M3 21h18"/><rect x="5" y="13" width="4" height="8"/><rect x="10" y="7" width="4" height="14"/><rect x="15" y="10" width="4" height="11"/></svg>;
    case "doc": return <svg viewBox="0 0 24 24" {...props}><path d="M7 3h8l5 5v13a1 1 0 0 1-1 1H7a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1Z"/><path d="M14 3v6h6M9 14h7M9 18h7"/></svg>;
    case "card": return <svg viewBox="0 0 24 24" {...props}><rect x="3" y="6" width="18" height="13" rx="2"/><path d="M3 10h18M7 15h3"/></svg>;
    case "phone": return <svg viewBox="0 0 24 24" {...props}><path d="M5 4h4l2 5-3 2a12 12 0 0 0 5 5l2-3 5 2v4a2 2 0 0 1-2 2A16 16 0 0 1 3 6a2 2 0 0 1 2-2Z"/></svg>;
    case "search": return <svg viewBox="0 0 24 24" {...props}><circle cx="11" cy="11" r="6"/><path d="m20 20-4-4"/></svg>;
    case "alert": return <svg viewBox="0 0 24 24" {...props}><circle cx="12" cy="12" r="9"/><path d="M12 8v5M12 16v.5"/></svg>;
    case "arrow": return <svg viewBox="0 0 24 24" {...props}><path d="M5 12h14M13 6l6 6-6 6"/></svg>;
    case "x": return <svg viewBox="0 0 24 24" {...props}><path d="M4 4l16 16M20 4 4 20"/></svg>;
    case "yt": return <svg viewBox="0 0 24 24" {...props}><rect x="2" y="6" width="20" height="12" rx="3"/><path d="m10 9 5 3-5 3V9Z" fill="currentColor"/></svg>;
    case "ig": return <svg viewBox="0 0 24 24" {...props}><rect x="3" y="3" width="18" height="18" rx="5"/><circle cx="12" cy="12" r="4"/><circle cx="17.5" cy="6.5" r="0.6" fill="currentColor"/></svg>;
    default: return null;
  }
};

Object.assign(window, { TileFace, HeroTilesArt, TileField, Icon });
