// 服务商图标组件
// 根据 provider code 返回内联 SVG 图标，全离线、绝对不会 404
import { Bot, Cloud, Terminal, Zap } from 'lucide-react'

export function ProviderIcon({ code, size = 20 }) {
  const s = size
  const half = s / 2
  const r = half - 1

  // 通义千问 / 百炼 — 阿里云橙
  if (code === 'qwen' || code === 'bailian') {
    return (
      <svg width={s} height={s} viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" aria-label="Qwen">
        <defs>
          <linearGradient id="pi-qwen" x1="0" y1="0" x2="1" y2="1">
            <stop offset="0%" stopColor="#FF8A00" />
            <stop offset="100%" stopColor="#FF4D00" />
          </linearGradient>
        </defs>
        <rect x="1" y="1" width="22" height="22" rx="6" fill="url(#pi-qwen)" />
        <text
          x="12" y="16.5" textAnchor="middle"
          fontFamily="-apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif"
          fontSize="12" fontWeight="700" fill="#fff"
        >Q</text>
      </svg>
    )
  }

  // DeepSeek — 深蓝
  if (code === 'deepseek') {
    return (
      <svg width={s} height={s} viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" aria-label="DeepSeek">
        <circle cx="12" cy="12" r="11" fill="#1A56DB" />
        <text
          x="12" y="15.5" textAnchor="middle"
          fontFamily="-apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif"
          fontSize="9" fontWeight="700" fill="#fff"
        >DS</text>
      </svg>
    )
  }

  // Kimi / Moonshot — 黑
  if (code === 'moonshot' || code === 'kimi') {
    return (
      <svg width={s} height={s} viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" aria-label="Kimi">
        <circle cx="12" cy="12" r="11" fill="#0F0F0F" />
        <text
          x="12" y="15.5" textAnchor="middle"
          fontFamily="-apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif"
          fontSize="8" fontWeight="700" fill="#fff"
        >Kimi</text>
      </svg>
    )
  }

  // Minimax — 紫
  if (code === 'minimax') {
    return (
      <svg width={s} height={s} viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" aria-label="Minimax">
        <circle cx="12" cy="12" r="11" fill="#7C3AED" />
        <text
          x="12" y="15.5" textAnchor="middle"
          fontFamily="-apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif"
          fontSize="9" fontWeight="700" fill="#fff"
        >MM</text>
      </svg>
    )
  }

  // Claude — Anthropic 橙棕
  if (code === 'claude' || code === 'anthropic') {
    return (
      <svg width={s} height={s} viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" aria-label="Claude">
        <circle cx="12" cy="12" r="11" fill="#D97757" />
        <text
          x="12" y="15.5" textAnchor="middle"
          fontFamily="-apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif"
          fontSize="11" fontWeight="700" fill="#fff"
        >C</text>
      </svg>
    )
  }

  // 执行内核 — 闪电
  if (code === 'skill_engine') {
    return <Zap size={s} strokeWidth={2.2} color="#2563EB" />
  }

  if (code === 'agentrun') {
    return <Cloud size={s} strokeWidth={2.2} color="#FF6A00" />
  }

  if (String(code || '').startsWith('local-')) {
    return <Terminal size={s} strokeWidth={2.1} color="#475569" />
  }

  // OpenAI / 通用兼容 — 机器人
  if (code === 'openai' || code === 'openai_compat') {
    return <Bot size={s} strokeWidth={2} color="#10A37F" />
  }

  // 兜底：灰色机器人
  return <Bot size={s} strokeWidth={2} color="#6B7280" />
}

export default ProviderIcon
