// icons.jsx — 小企鹅吉祥物 + 金币 + 分类/导航图标
// 全部导出到 window，供 app.jsx 使用。无外部依赖。

// ---------- 小企鹅吉祥物 ----------
// 用一张透明 PNG (app/penguin.png) 渲染。
// glow: 是否在身后加一圈青色柔光（深色屏幕 / 锁屏用）。
// mood 参数保留以兼容调用处，图片版本不再区分表情。
function Penguin({ size = 120, mood = 'happy', glow = false, style }) {
  // 阴影随尺寸自适应：深色投影做出立体感，淡白描边在深色背景下勾出轮廓
  const blur = Math.max(3, Math.round(size * 0.08));
  const dy = Math.max(1, Math.round(size * 0.05));
  const rim = Math.max(1, Math.round(size * 0.03));
  let filter =
    `drop-shadow(0 ${dy}px ${blur}px rgba(0,0,0,.45)) ` +
    `drop-shadow(0 0 ${rim}px rgba(255,255,255,.35))`;
  if (glow) filter += ` drop-shadow(0 0 ${Math.round(size * 0.16)}px rgba(34,211,238,.5))`;
  return (
    <img
      src="app/penguin.png"
      alt="金币小企鹅"
      style={{ width: size, height: size, display: 'block', objectFit: 'contain', filter, ...style }}
    />
  );
}

// ---------- 金币 ----------
function Coin({ size = 24, style }) {
  return (
    <svg viewBox="0 0 24 24" style={{ width: size, height: size, ...style }} aria-hidden="true">
      <defs>
        <linearGradient id="coin-g" x1="0" y1="0" x2="0" y2="1">
          <stop offset="0%" stopColor="#ffe14d" />
          <stop offset="100%" stopColor="#ffb01f" />
        </linearGradient>
      </defs>
      <circle cx="12" cy="12" r="10" fill="url(#coin-g)" />
      <circle cx="12" cy="12" r="7.4" fill="none" stroke="#f59e0b" strokeWidth="1.3" opacity="0.6" />
      <path d="M12 7.2 l1.5 3.1 3.4 .5 -2.45 2.4 .58 3.38L12 15l-3.06 1.6.58-3.38L7.07 10.8l3.4-.5z" fill="#fff" opacity="0.92" />
    </svg>
  );
}

// ---------- 通用小图标 (24x24, currentColor stroke) ----------
const Ic = (p) => (
  <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={p.sw || 2}
    strokeLinecap="round" strokeLinejoin="round"
    style={{ width: p.size || 24, height: p.size || 24, ...p.style }} aria-hidden="true">{p.children}</svg>
);
const IconHome = (p) => <Ic {...p}><path d="M3 11l9-8 9 8" /><path d="M5 10v10h14V10" /></Ic>;
const IconPlus = (p) => <Ic {...p}><path d="M12 5v14M5 12h14" /></Ic>;
const IconChat = (p) => <Ic {...p}><path d="M21 12a8 8 0 0 1-11.5 7.2L4 20l1-4.5A8 8 0 1 1 21 12z" /><circle cx="9" cy="12" r="1" fill="currentColor" stroke="none"/><circle cx="12" cy="12" r="1" fill="currentColor" stroke="none"/><circle cx="15" cy="12" r="1" fill="currentColor" stroke="none"/></Ic>;
const IconBack = (p) => <Ic {...p}><path d="M15 5l-7 7 7 7" /></Ic>;
const IconLock = (p) => <Ic {...p}><rect x="5" y="11" width="14" height="9" rx="2" /><path d="M8 11V8a4 4 0 0 1 8 0v3" /></Ic>;
const IconDelete = (p) => <Ic {...p}><path d="M20 6H9L4 12l5 6h11a1 1 0 0 0 1-1V7a1 1 0 0 0-1-1z" /><path d="M15 10l-4 4M11 10l4 4" /></Ic>;
const IconSend = (p) => <Ic {...p}><path d="M5 12l15-7-5 15-3.5-5.5L5 12z" /><path d="M11.5 14.5L20 5" /></Ic>;
const IconUp = (p) => <Ic {...p}><path d="M12 19V6M6 12l6-6 6 6" /></Ic>;
const IconDown = (p) => <Ic {...p}><path d="M12 5v13M6 12l6 6 6-6" /></Ic>;
const IconCheck = (p) => <Ic {...p}><path d="M5 13l4 4L19 7" /></Ic>;
const IconSpark = (p) => <Ic {...p}><path d="M12 3l1.8 5.2L19 10l-5.2 1.8L12 17l-1.8-5.2L5 10l5.2-1.8z" /></Ic>;
const IconSun = (p) => <Ic {...p}><circle cx="12" cy="12" r="4.2" /><path d="M12 2.5v2M12 19.5v2M4.5 12h-2M21.5 12h-2M6.3 6.3L4.9 4.9M19.1 19.1l-1.4-1.4M17.7 6.3l1.4-1.4M4.9 19.1l1.4-1.4" /></Ic>;
const IconMoon = (p) => <Ic {...p}><path d="M20 14.5A8 8 0 0 1 9.5 4 7 7 0 1 0 20 14.5z" /></Ic>;
const IconHistory = (p) => <Ic {...p}><path d="M3 12a9 9 0 1 0 3-6.7L3 8" /><path d="M3 4v4h4" /><path d="M12 8v4l3 2" /></Ic>;
const IconTrash = (p) => <Ic {...p}><path d="M4 7h16M9 7V5a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2M6 7l1 13a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1l1-13" /></Ic>;
// 梦想（灯泡/愿望）
const IconDream = (p) => <Ic {...p}><path d="M12 3c3.4 0 5.6 2.7 5.6 6.1 0 4-3 7.1-5.6 7.1S6.4 13.1 6.4 9.1C6.4 5.7 8.6 3 12 3z" /><path d="M12 16.2c-.7 1-.7 2.1 0 3.1M10.5 21h3" /></Ic>;
// 气球（放飞）
const IconBalloon = (p) => <Ic {...p}><path d="M12 2.5c3 0 5 2.4 5 5.6 0 3.7-2.7 6.5-5 6.5s-5-2.8-5-6.5C7 4.9 9 2.5 12 2.5z" /><path d="M12 14.6c-.6.9-.6 1.8 0 2.7M11 21l1-3.7 1 3.7z" /></Ic>;

// 主题切换按钮
function ThemeToggle({ theme, onToggle }) {
  return (
    <button className="theme-toggle" onClick={onToggle} aria-label="切换日间/夜间">
      {theme === 'dark' ? <IconSun size={20} /> : <IconMoon size={19} />}
    </button>
  );
}

// ---------- 分类图标 (emoji 风的纯 SVG, 36x36) ----------
function CatIcon({ id, size = 32 }) {
  const wrap = (children, bg) => (
    <svg viewBox="0 0 36 36" style={{ width: size, height: size }} aria-hidden="true">
      <rect width="36" height="36" rx="11" fill={bg} />
      <g transform="translate(7 7)" stroke="#1b2433" strokeWidth="1.8" fill="none" strokeLinecap="round" strokeLinejoin="round">{children}</g>
    </svg>
  );
  switch (id) {
    case 'allowance': // 家长存零花钱 - 钱袋
      return wrap(<>
        <path d="M4 9c-1.6 2.4-2.4 5.4-2.4 7.8 0 2.6 3.4 3.7 7.9 3.7s7.9-1.1 7.9-3.7c0-2.4-.8-5.4-2.4-7.8z" fill="#ffd56b" />
        <path d="M4 9c1.4-1.3 3.6-1.9 5.5-1.9s4.1.6 5.5 1.9" fill="#ffe9a8" />
        <path d="M6.5 7C5.3 5.4 5.5 3.4 7 2.4c.4 1.3 1.5 1.8 2.5 1.8s2.1-.5 2.5-1.8c1.5 1 1.7 3 .5 4.6" fill="#ffe9a8" />
        <path d="M9.5 12.2v4.3M7.5 12l2 2.2 2-2.2M7.7 14.6h3.6M7.7 16.1h3.6" />
      </>, '#fff3c4');
    case 'reward': // 奖励 - 奖牌
      return wrap(<>
        <path d="M7 2l3 6M15 2l-3 6" /><circle cx="11" cy="14" r="6" fill="#ffe14d" />
        <path d="M11 11l1 2 2 .2-1.5 1.4.4 2L11 15.6 9.1 16.6l.4-2L8 13.2l2-.2z" fill="#fff" stroke="none" />
      </>, '#fff3c4');
    case 'toy': // 玩具 - 积木
      return wrap(<>
        <rect x="2" y="10" width="9" height="9" rx="1.5" fill="#8ee6ff" />
        <rect x="12" y="6" width="8" height="8" rx="1.5" fill="#b9f06e" />
        <circle cx="6.5" cy="8" r="2" fill="#ff9b3d" />
      </>, '#d8f3ff');
    case 'snack': // 零食 - 棒棒糖/糖果
      return wrap(<>
        <circle cx="9" cy="8" r="6" fill="#ff8fa8" /><path d="M9 14v7" />
        <path d="M6 8a3 3 0 0 1 6 0" stroke="#fff" />
      </>, '#ffe1e8');
    case 'stationery': // 文具 - 铅笔
      return wrap(<>
        <path d="M3 18l2-5L16 2l3 3L8 16z" fill="#ffd56b" /><path d="M14 4l3 3" /><path d="M3 18l2-1" />
      </>, '#fff0cf');
    case 'gift': // 礼物
      return wrap(<>
        <rect x="2" y="9" width="18" height="11" rx="1.5" fill="#c9b8ff" /><path d="M2 13h18M11 9v11" />
        <path d="M11 9C8 9 6 4 11 4c5 0 3 5 0 5z" fill="#ff9b3d" />
      </>, '#ece5ff');
    case 'book': // 书/学习
      return wrap(<>
        <path d="M2 4h7c1.5 0 2 1 2 2v14c0-1-.5-2-2-2H2z" fill="#8ee6ff" />
        <path d="M20 4h-7c-1.5 0-2 1-2 2v14c0-1 .5-2 2-2h7z" fill="#b9f06e" />
      </>, '#e6f7ff');
    case 'wish': // 许愿 - 流星愿望
      return wrap(<>
        <path d="M10 1.5l1.9 4.5 4.8.4-3.6 3.2 1.1 4.7L10 11.9 5.8 14.3l1.1-4.7L3.3 6.4l4.8-.4z" fill="#ffd56b" />
        <path d="M2 17l2-2M5 19l1.5-1.5" stroke="#ff9b3d" />
      </>, '#fff0cf');
    default: // 其他 - 星星
      return wrap(<>
        <path d="M11 2l2.6 6.3L20 9l-5 4.4L16.5 20 11 16.5 5.5 20 7 13.4 2 9l6.4-.7z" fill="#ffd56b" />
      </>, '#f1ecff');
  }
}

Object.assign(window, {
  Penguin, Coin, CatIcon,
  IconHome, IconPlus, IconChat, IconBack, IconLock, IconDelete,
  IconSend, IconUp, IconDown, IconCheck, IconSpark, IconSun, IconMoon, ThemeToggle,
  IconHistory, IconTrash, IconDream, IconBalloon,
});
