/* global React */
const { useState } = React;

/* ============================================================
 * TILE ICONS — flat illustrative SVGs sized to a 64x64 viewport.
 * Each draws on a solid colored tile (white shapes + tonal depth).
 * Style: filled silhouettes, no strokes, slight overlap for warmth.
 * ============================================================ */

const TileIcon = ({ name, size = 60 }) => {
  const Common = ({ children }) => (
    <svg viewBox="0 0 64 64" width={size} height={size} aria-hidden="true">{children}</svg>
  );

  switch (name) {
    /* Производство */
    case 'batches': // candles
      return (
        <Common>
          {/* back candle */}
          <rect x="14" y="26" width="10" height="22" rx="2" fill="#ffffff" opacity="0.55"/>
          <path d="M19 18c-2 3 0 5 0 6 1 0 3-2 0-6z" fill="#FFE0B2" opacity="0.85"/>
          {/* main candle */}
          <rect x="26" y="20" width="14" height="28" rx="2.5" fill="#ffffff"/>
          <rect x="26" y="20" width="14" height="6" rx="2.5" fill="#FFF4E1"/>
          <line x1="33" y1="10" x2="33" y2="20" stroke="#3a1a06" strokeWidth="1.2" strokeLinecap="round"/>
          <path d="M33 4c-3 4-2 7 0 9 2-2 3-5 0-9z" fill="#FFD37A"/>
          <path d="M33 6c-1.5 2-1 4 0 5 1-1 1.5-3 0-5z" fill="#fff"/>
          {/* front candle */}
          <rect x="42" y="30" width="10" height="18" rx="2" fill="#ffffff" opacity="0.7"/>
          <path d="M47 24c-2 3 0 5 0 6 1 0 3-2 0-6z" fill="#FFE0B2" opacity="0.85"/>
          <rect x="10" y="48" width="46" height="3" rx="1.5" fill="#000" opacity="0.18"/>
        </Common>
      );

    case 'recipes': // dropper bottle + leaf
      return (
        <Common>
          <path d="M20 10h14v6l3 3v22a4 4 0 0 1-4 4h-12a4 4 0 0 1-4-4V19l3-3z" fill="#ffffff"/>
          <rect x="22" y="10" width="10" height="3" rx="1" fill="#fff" opacity="0.7"/>
          <path d="M22 26h10v4H22z" fill="#E5D9F5"/>
          <circle cx="27" cy="36" r="3" fill="#A06CD5"/>
          <path d="M44 14c5 2 8 7 6 12-4-1-7-5-6-12z" fill="#7BC480"/>
          <path d="M44 14c-1 4 1 8 6 12" stroke="#fff" strokeWidth="1.2" fill="none" opacity="0.6"/>
        </Common>
      );

    case 'materials': // open box w/ smaller boxes
      return (
        <Common>
          <path d="M10 22 32 12l22 10v22l-22 10-22-10z" fill="#ffffff"/>
          <path d="M10 22 32 32l22-10" stroke="#FFE6D1" strokeWidth="2" fill="none"/>
          <path d="M32 32v22" stroke="#FFE6D1" strokeWidth="2"/>
          <path d="M10 22 32 32 10 30z" fill="#FFD7B3" opacity="0.6"/>
          <rect x="18" y="34" width="8" height="6" rx="1" fill="#FF8A4C"/>
          <rect x="28" y="36" width="6" height="5" rx="1" fill="#FFB37A"/>
        </Common>
      );

    case 'defects': // cracked candle
      return (
        <Common>
          <rect x="22" y="20" width="20" height="28" rx="3" fill="#ffffff"/>
          <path d="M30 24 26 36l5 2-3 8" stroke="#C13434" strokeWidth="2" fill="none" strokeLinejoin="round" strokeLinecap="round"/>
          <circle cx="48" cy="18" r="6" fill="#FFD37A"/>
          <path d="M48 14v4M48 22v-1" stroke="#7a3a06" strokeWidth="1.5" strokeLinecap="round"/>
          <circle cx="48" cy="23" r="0.8" fill="#7a3a06"/>
        </Common>
      );

    /* Продажи */
    case 'orders': // receipt with check
      return (
        <Common>
          <path d="M14 8h32v50l-4-3-4 3-4-3-4 3-4-3-4 3-4-3-4 3z" fill="#ffffff"/>
          <rect x="20" y="16" width="20" height="2.5" rx="1" fill="#9FB4E8"/>
          <rect x="20" y="22" width="14" height="2.5" rx="1" fill="#C8D2EF"/>
          <rect x="20" y="28" width="18" height="2.5" rx="1" fill="#9FB4E8"/>
          <circle cx="42" cy="40" r="9" fill="#4A6FD8"/>
          <path d="m38 40 3 3 6-6" stroke="#fff" strokeWidth="2.4" strokeLinecap="round" strokeLinejoin="round" fill="none"/>
        </Common>
      );

    case 'inventory': // stack of boxes
      return (
        <Common>
          <rect x="12" y="32" width="18" height="16" rx="2" fill="#ffffff"/>
          <rect x="12" y="32" width="18" height="3" fill="#D9E8DD"/>
          <rect x="30" y="32" width="22" height="16" rx="2" fill="#ffffff" opacity="0.9"/>
          <rect x="30" y="32" width="22" height="3" fill="#D9E8DD"/>
          <rect x="22" y="14" width="22" height="18" rx="2" fill="#ffffff"/>
          <rect x="22" y="14" width="22" height="3.5" fill="#D9E8DD"/>
          <path d="M33 20v6M30 23h6" stroke="#3A8050" strokeWidth="2" strokeLinecap="round"/>
        </Common>
      );

    case 'customers': // two people
      return (
        <Common>
          <circle cx="22" cy="24" r="8" fill="#ffffff"/>
          <path d="M10 50c0-7 5-12 12-12s12 5 12 12" fill="#ffffff"/>
          <circle cx="42" cy="26" r="6" fill="#ffffff" opacity="0.75"/>
          <path d="M34 50c0-5 4-9 8-9s8 4 8 9" fill="#ffffff" opacity="0.75"/>
          <circle cx="22" cy="22" r="3" fill="#C44B5C" opacity="0.4"/>
          <circle cx="42" cy="25" r="2" fill="#C44B5C" opacity="0.4"/>
        </Common>
      );

    case 'shipping': // delivery truck
      return (
        <Common>
          <rect x="6" y="22" width="28" height="20" rx="2" fill="#ffffff"/>
          <path d="M34 28h10l8 8v6H34z" fill="#ffffff" opacity="0.9"/>
          <rect x="36" y="30" width="9" height="6" rx="1" fill="#A8DCF0"/>
          <circle cx="18" cy="44" r="5" fill="#2E5468"/>
          <circle cx="18" cy="44" r="2.2" fill="#fff"/>
          <circle cx="42" cy="44" r="5" fill="#2E5468"/>
          <circle cx="42" cy="44" r="2.2" fill="#fff"/>
          <path d="M10 28h12M10 32h8" stroke="#A8DCF0" strokeWidth="2" strokeLinecap="round"/>
        </Common>
      );

    /* Каналы */
    case 'ozon': // stylized "Oz" mark
      return (
        <Common>
          <circle cx="32" cy="32" r="22" fill="#ffffff"/>
          <text x="32" y="40" textAnchor="middle"
                fontFamily='"SF Pro Display", -apple-system, system-ui, sans-serif'
                fontSize="20" fontWeight="800" fill="#0066FF" letterSpacing="-0.5">OZ</text>
          <circle cx="32" cy="32" r="22" fill="none" stroke="#0066FF" strokeOpacity="0.16" strokeWidth="1"/>
        </Common>
      );

    case 'telegram':
      return (
        <Common>
          <circle cx="32" cy="32" r="22" fill="#ffffff"/>
          <path d="M44 22 22 32l6 3 2 8 4-5 8 6z" fill="#3FA9E5"/>
        </Common>
      );

    case 'instagram':
      return (
        <Common>
          <rect x="14" y="14" width="36" height="36" rx="9" fill="#ffffff"/>
          <rect x="14" y="14" width="36" height="36" rx="9" fill="none" stroke="#E1306C" strokeWidth="3"/>
          <circle cx="32" cy="32" r="8" fill="none" stroke="#E1306C" strokeWidth="3"/>
          <circle cx="42" cy="22" r="2.2" fill="#E1306C"/>
        </Common>
      );

    case 'whatsapp':
      return (
        <Common>
          <circle cx="32" cy="32" r="22" fill="#ffffff"/>
          <path d="M22 42 24 36a10 10 0 1 1 4 4z" fill="#25D366"/>
          <path d="M28 32c0 3 3 6 6 6l2-1 2 2-2 2c-5 0-10-5-10-10l2-2 2 2z" fill="#fff"/>
        </Common>
      );

    /* Деньги */
    case 'revenue': // chart bars
      return (
        <Common>
          <rect x="12" y="32" width="8" height="18" rx="1.5" fill="#ffffff" opacity="0.7"/>
          <rect x="24" y="24" width="8" height="26" rx="1.5" fill="#ffffff" opacity="0.85"/>
          <rect x="36" y="18" width="8" height="32" rx="1.5" fill="#ffffff"/>
          <path d="m14 28 12-8 12-6 10-2" stroke="#fff" strokeWidth="2.5" fill="none" strokeLinecap="round"/>
          <circle cx="48" cy="12" r="3" fill="#fff"/>
        </Common>
      );

    case 'payments': // ruble + check
      return (
        <Common>
          <circle cx="32" cy="32" r="20" fill="#ffffff"/>
          <text x="32" y="40" textAnchor="middle"
                fontFamily='"SF Pro Display", -apple-system, system-ui, sans-serif'
                fontSize="26" fontWeight="800" fill="#C39434">₽</text>
          <circle cx="46" cy="46" r="9" fill="#3A8050"/>
          <path d="m42 46 3 3 5-5" stroke="#fff" strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round" fill="none"/>
        </Common>
      );

    case 'robokassa': // robot
      return (
        <Common>
          <rect x="16" y="20" width="32" height="26" rx="6" fill="#ffffff"/>
          <rect x="20" y="40" width="6" height="8" rx="1" fill="#fff"/>
          <rect x="38" y="40" width="6" height="8" rx="1" fill="#fff"/>
          <line x1="32" y1="14" x2="32" y2="20" stroke="#fff" strokeWidth="2" strokeLinecap="round"/>
          <circle cx="32" cy="12" r="3" fill="#fff"/>
          <circle cx="25" cy="32" r="3.5" fill="#6B4DB8"/>
          <circle cx="39" cy="32" r="3.5" fill="#6B4DB8"/>
          <rect x="26" y="38" width="12" height="2" rx="1" fill="#6B4DB8"/>
        </Common>
      );

    /* Сегодня / общие */
    case 'tasks': // checklist
      return (
        <Common>
          <rect x="14" y="12" width="36" height="40" rx="4" fill="#ffffff"/>
          <rect x="20" y="20" width="5" height="5" rx="1" fill="#4A8FD8"/>
          <path d="m21 22.5 1.2 1.2 2-2" stroke="#fff" strokeWidth="1.3" strokeLinecap="round" fill="none"/>
          <rect x="28" y="20" width="16" height="3" rx="1" fill="#B8D1EE"/>
          <rect x="20" y="29" width="5" height="5" rx="1" fill="#4A8FD8"/>
          <path d="m21 31.5 1.2 1.2 2-2" stroke="#fff" strokeWidth="1.3" strokeLinecap="round" fill="none"/>
          <rect x="28" y="29" width="18" height="3" rx="1" fill="#B8D1EE"/>
          <rect x="20" y="38" width="5" height="5" rx="1" fill="none" stroke="#4A8FD8" strokeWidth="1.4"/>
          <rect x="28" y="38" width="14" height="3" rx="1" fill="#D8E5F3"/>
        </Common>
      );

    case 'analytics': // pie chart
      return (
        <Common>
          <circle cx="32" cy="32" r="20" fill="#ffffff"/>
          <path d="M32 12a20 20 0 0 1 20 20H32z" fill="#D6B0BD"/>
          <path d="M52 32a20 20 0 0 1-11 18l-9-18z" fill="#E29CAF"/>
          <circle cx="32" cy="32" r="6" fill="#fff"/>
        </Common>
      );

    case 'team': // 3 avatars
      return (
        <Common>
          <circle cx="22" cy="24" r="7" fill="#ffffff"/>
          <circle cx="32" cy="22" r="8" fill="#ffffff"/>
          <circle cx="42" cy="24" r="7" fill="#ffffff" opacity="0.85"/>
          <path d="M12 50c0-7 5-12 12-12s12 5 12 12" fill="#ffffff"/>
          <path d="M28 50c0-7 5-12 12-12s12 5 12 12" fill="#ffffff" opacity="0.7"/>
        </Common>
      );

    case 'export': // box with arrow up
      return (
        <Common>
          <rect x="10" y="28" width="44" height="22" rx="3" fill="#ffffff"/>
          <path d="M32 14v18M24 22l8-8 8 8" stroke="#fff" strokeWidth="3" strokeLinecap="round" strokeLinejoin="round" fill="none"/>
          <rect x="20" y="36" width="24" height="8" rx="2" fill="none" stroke="#8896A8" strokeWidth="1.5" opacity="0.4"/>
        </Common>
      );

    /* AI ассистент */
    case 'ai':
      return (
        <Common>
          <path d="M32 8 36 28l20 4-20 4-4 20-4-20-20-4 20-4z" fill="#ffffff"/>
          <path d="M48 12 50 18l6 2-6 2-2 6-2-6-6-2 6-2z" fill="#fff" opacity="0.85"/>
          <path d="M14 40 16 44l4 2-4 2-2 4-2-4-4-2 4-2z" fill="#fff" opacity="0.75"/>
        </Common>
      );

    /* Onboarding */
    case 'onboarding': // ring + check
      return (
        <Common>
          <circle cx="32" cy="32" r="20" fill="none" stroke="#ffffff" strokeOpacity="0.4" strokeWidth="6"/>
          <path d="M32 12a20 20 0 0 1 17 30" fill="none" stroke="#fff" strokeWidth="6" strokeLinecap="round"/>
          <circle cx="32" cy="32" r="11" fill="#ffffff"/>
          <path d="m26 32 4 4 8-8" stroke="#E08544" strokeWidth="2.5" strokeLinecap="round" strokeLinejoin="round" fill="none"/>
        </Common>
      );

    case 'settings':
      return (
        <Common>
          <path d="M32 8 36 12 42 10 44 16 50 18 50 24 54 28 50 32 54 36 50 38 50 44 44 46 42 52 36 50 32 54 28 50 22 52 20 46 14 44 14 38 10 36 14 32 10 28 14 24 14 18 20 16 22 10 28 12z" fill="#ffffff"/>
          <circle cx="32" cy="32" r="8" fill="#8896A8"/>
        </Common>
      );

    /* iOS-style nav icons (line, monochrome) */
    case 'nav-home':
      return <svg viewBox="0 0 24 24" width={size} height={size} fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M3 11.5 12 4l9 7.5"/><path d="M5 10v10h14V10"/></svg>;
    case 'nav-tasks':
      return <svg viewBox="0 0 24 24" width={size} height={size} fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><circle cx="12" cy="12" r="9"/><path d="m8 12 3 3 5-6"/></svg>;
    case 'nav-inbox':
      return <svg viewBox="0 0 24 24" width={size} height={size} fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M3 13h5l2 3h4l2-3h5"/><path d="M5 5h14l2 8v6H3v-6z"/></svg>;
    case 'nav-search':
      return <svg viewBox="0 0 24 24" width={size} height={size} fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><circle cx="11" cy="11" r="7"/><path d="m21 21-4.3-4.3"/></svg>;
    case 'nav-account':
      return <svg viewBox="0 0 24 24" width={size} height={size} fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><circle cx="12" cy="9" r="4"/><path d="M4 21a8 8 0 0 1 16 0"/></svg>;
    case 'mic':
      return <svg viewBox="0 0 24 24" width={size} height={size} fill="none" stroke="currentColor" strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round"><rect x="9" y="3" width="6" height="12" rx="3"/><path d="M5 11a7 7 0 0 0 14 0M12 18v3"/></svg>;
    case 'plus':
      return <svg viewBox="0 0 24 24" width={size} height={size} fill="none" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round" strokeLinejoin="round"><path d="M12 5v14M5 12h14"/></svg>;
    case 'chev':
      return <svg viewBox="0 0 24 24" width={size} height={size} fill="none" stroke="currentColor" strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round"><path d="m9 6 6 6-6 6"/></svg>;
    case 'sliders':
      return <svg viewBox="0 0 24 24" width={size} height={size} fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M4 6h10M4 12h6M4 18h13"/><circle cx="17" cy="6" r="2.2"/><circle cx="13" cy="12" r="2.2"/><circle cx="20" cy="18" r="2.2"/></svg>;
    default:
      return null;
  }
};

window.TileIcon = TileIcon;
