// 图标库配置工具
// 用于方便地切换不同的图标库

export interface IconLibraryConfig {
  name: string
  prefix: string
  displayName: string
  description: string
  apiUrl: string
}

// 支持的图标库配置
export const iconLibraries: Record<string, IconLibraryConfig> = {
  // 特殊选项：显示所有图标库
  all: {
    name: 'all',
    prefix: 'all',
    displayName: 'All Icons',
    description: '显示所有图标库的图标，支持全局搜索',
    apiUrl: 'https://api.iconify.design/collections'
  },
  
  // 原有图标库
  tabler: {
    name: 'tabler',
    prefix: 'tabler',
    displayName: 'Tabler Icons',
    description: '现代、简洁的SVG图标库 (5,963个图标)',
    apiUrl: 'https://api.iconify.design/collection?prefix=tabler'
  },
  heroicons: {
    name: 'heroicons',
    prefix: 'heroicons',
    displayName: 'Heroicons',
    description: '由Tailwind CSS团队制作的精美图标 (1,288个图标)',
    apiUrl: 'https://api.iconify.design/collection?prefix=heroicons'
  },
  lucide: {
    name: 'lucide',
    prefix: 'lucide',
    displayName: 'Lucide',
    description: 'Feather图标的社区延续',
    apiUrl: 'https://api.iconify.design/collection?prefix=lucide'
  },
  material: {
    name: 'material',
    prefix: 'material-symbols',
    displayName: 'Material Symbols',
    description: 'Google Material Design图标',
    apiUrl: 'https://api.iconify.design/collection?prefix=material-symbols'
  },
  carbon: {
    name: 'carbon',
    prefix: 'carbon',
    displayName: 'Carbon Icons',
    description: 'IBM Carbon Design System图标 (2,392个图标)',
    apiUrl: 'https://api.iconify.design/collection?prefix=carbon'
  },
  feather: {
    name: 'feather',
    prefix: 'feather',
    displayName: 'Feather Icons',
    description: '简洁美观的线性图标 (286个图标)',
    apiUrl: 'https://api.iconify.design/collection?prefix=feather'
  },
  
  // MIT协议 Top 30 图标库（按数量排序）
  fluent: {
    name: 'fluent',
    prefix: 'fluent',
    displayName: 'Fluent UI System Icons',
    description: 'Microsoft官方风格，企业级项目首选 (18,519个图标)',
    apiUrl: 'https://api.iconify.design/collection?prefix=fluent'
  },
  phosphor: {
    name: 'phosphor',
    prefix: 'ph',
    displayName: 'Phosphor',
    description: '多风格可选，设计现代 (9,072个图标)',
    apiUrl: 'https://api.iconify.design/collection?prefix=ph'
  },
  hugeicons: {
    name: 'hugeicons',
    prefix: 'hugeicons',
    displayName: 'Huge Icons',
    description: '图标数量大，种类丰富 (4,556个图标)',
    apiUrl: 'https://api.iconify.design/collection?prefix=hugeicons'
  },
  'fluent-emoji-flat': {
    name: 'fluent-emoji-flat',
    prefix: 'fluent-emoji-flat',
    displayName: 'Fluent Emoji Flat',
    description: 'Emoji图标集，平面风格 (3,145个图标)',
    apiUrl: 'https://api.iconify.design/collection?prefix=fluent-emoji-flat'
  },
  mynaui: {
    name: 'mynaui',
    prefix: 'mynaui',
    displayName: 'Myna UI Icons',
    description: 'UI设计友好，企业级项目 (2,544个图标)',
    apiUrl: 'https://api.iconify.design/collection?prefix=mynaui'
  },
  tdesign: {
    name: 'tdesign',
    prefix: 'tdesign',
    displayName: 'TDesign Icons',
    description: '腾讯设计团队，企业级项目首选 (2,130个图标)',
    apiUrl: 'https://api.iconify.design/collection?prefix=tdesign'
  },
  'token-branded': {
    name: 'token-branded',
    prefix: 'token-branded',
    displayName: 'Web3 Icons Branded',
    description: 'Web3相关品牌图标，区块链项目 (2,000个图标)',
    apiUrl: 'https://api.iconify.design/collection?prefix=token-branded'
  },
  token: {
    name: 'token',
    prefix: 'token',
    displayName: 'Web3 Icons',
    description: 'Web3主题图标，适合加密/区块链界面 (1,746个图标)',
    apiUrl: 'https://api.iconify.design/collection?prefix=token'
  },
  'fluent-emoji-high-contrast': {
    name: 'fluent-emoji-high-contrast',
    prefix: 'fluent-emoji-high-contrast',
    displayName: 'Fluent Emoji High Contrast',
    description: '高对比度Emoji，适合无障碍设计 (1,595个图标)',
    apiUrl: 'https://api.iconify.design/collection?prefix=fluent-emoji-high-contrast'
  },
  iconoir: {
    name: 'iconoir',
    prefix: 'iconoir',
    displayName: 'Iconoir',
    description: '风格现代、简洁，适合Web和移动端 (1,671个图标)',
    apiUrl: 'https://api.iconify.design/collection?prefix=iconoir'
  },
  ion: {
    name: 'ion',
    prefix: 'ion',
    displayName: 'IonIcons',
    description: 'Ionic团队，移动端和Web项目通用 (1,357个图标)',
    apiUrl: 'https://api.iconify.design/collection?prefix=ion'
  },
  'vscode-icons': {
    name: 'vscode-icons',
    prefix: 'vscode-icons',
    displayName: 'VSCode Icons',
    description: '编程相关图标，适合开发工具 (1,397个图标)',
    apiUrl: 'https://api.iconify.design/collection?prefix=vscode-icons'
  },
  'siemens-industrial': {
    name: 'siemens-industrial',
    prefix: 'ix',
    displayName: 'Siemens Industrial Icons',
    description: '工业风格图标，适合工业/硬件UI (1,407个图标)',
    apiUrl: 'https://api.iconify.design/collection?prefix=ix'
  },
  framework7: {
    name: 'framework7',
    prefix: 'f7',
    displayName: 'Framework7 Icons',
    description: '移动端Web项目图标，兼容性好 (1,253个图标)',
    apiUrl: 'https://api.iconify.design/collection?prefix=f7'
  },
  teenyicons: {
    name: 'teenyicons',
    prefix: 'teenyicons',
    displayName: 'Teenyicons',
    description: '极小图标集，适合微小界面元素 (1,200个图标)',
    apiUrl: 'https://api.iconify.design/collection?prefix=teenyicons'
  },
  dinkie: {
    name: 'dinkie',
    prefix: 'dinkie-icons',
    displayName: 'Dinkie Icons',
    description: '小型图标集，设计简洁 (1,198个图标)',
    apiUrl: 'https://api.iconify.design/collection?prefix=dinkie-icons'
  },
  'material-icon-theme': {
    name: 'material-icon-theme',
    prefix: 'material-icon-theme',
    displayName: 'Material Icon Theme',
    description: 'Material Design官方图标，UI项目首选 (1,106个图标)',
    apiUrl: 'https://api.iconify.design/collection?prefix=material-icon-theme'
  },
  clarity: {
    name: 'clarity',
    prefix: 'clarity',
    displayName: 'Clarity',
    description: 'VMware提供，企业级UI项目 (1,103个图标)',
    apiUrl: 'https://api.iconify.design/collection?prefix=clarity'
  },
  devicon: {
    name: 'devicon',
    prefix: 'devicon',
    displayName: 'Devicon',
    description: '编程和开发工具图标，适合技术相关页面 (957个图标)',
    apiUrl: 'https://api.iconify.design/collection?prefix=devicon'
  },
  jam: {
    name: 'jam',
    prefix: 'jam',
    displayName: 'Jam Icons',
    description: 'UI设计友好，风格多样 (940个图标)',
    apiUrl: 'https://api.iconify.design/collection?prefix=jam'
  },
  'devicon-plain': {
    name: 'devicon-plain',
    prefix: 'devicon-plain',
    displayName: 'Devicon Plain',
    description: 'Devicon的简化版，更轻量 (700个图标)',
    apiUrl: 'https://api.iconify.design/collection?prefix=devicon-plain'
  },
  gg: {
    name: 'gg',
    prefix: 'gg',
    displayName: 'css.gg',
    description: '小而美的UI图标，设计现代 (704个图标)',
    apiUrl: 'https://api.iconify.design/collection?prefix=gg'
  },
  lineicons: {
    name: 'lineicons',
    prefix: 'lineicons',
    displayName: 'Lineicons',
    description: '流行线性图标集，UI项目适用 (606个图标)',
    apiUrl: 'https://api.iconify.design/collection?prefix=lineicons'
  },
  fontisto: {
    name: 'fontisto',
    prefix: 'fontisto',
    displayName: 'Fontisto',
    description: '社交媒体和常用图标集合 (615个图标)',
    apiUrl: 'https://api.iconify.design/collection?prefix=fontisto'
  },
  healthicons: {
    name: 'healthicons',
    prefix: 'healthicons',
    displayName: 'Health Icons',
    description: '医疗和健康相关图标，专业项目 (2,024个图标)',
    apiUrl: 'https://api.iconify.design/collection?prefix=healthicons'
  },
  stash: {
    name: 'stash',
    prefix: 'stash',
    displayName: 'Stash Icons',
    description: '通用UI图标集，适合快速集成 (982个图标)',
    apiUrl: 'https://api.iconify.design/collection?prefix=stash'
  },
  si: {
    name: 'si',
    prefix: 'si',
    displayName: 'Sargam Icons',
    description: '多用途图标集，风格现代 (1,227个图标)',
    apiUrl: 'https://api.iconify.design/collection?prefix=si'
  },
  'ant-design': {
    name: 'ant-design',
    prefix: 'ant-design',
    displayName: 'Ant Design Icons',
    description: 'Ant Design官方图标，企业级UI项目 (830个图标)',
    apiUrl: 'https://api.iconify.design/collection?prefix=ant-design'
  }
}

// 获取图标库配置
export function getIconLibraryConfig(libraryName: string): IconLibraryConfig | null {
  return iconLibraries[libraryName] || null
}

// 获取所有可用的图标库
export function getAvailableIconLibraries(): IconLibraryConfig[] {
  const libraries = Object.values(iconLibraries)
  
  // 分离"All"选项和其他选项
  const allOption = libraries.find(lib => lib.name === 'all')
  const otherLibraries = libraries.filter(lib => lib.name !== 'all')
  
  // 其他选项按displayName字母顺序排序
  otherLibraries.sort((a, b) => a.displayName.localeCompare(b.displayName))
  
  // 将"All"选项放在第一位
  return allOption ? [allOption, ...otherLibraries] : otherLibraries
}

// 验证图标库名称
export function isValidIconLibrary(libraryName: string): boolean {
  return libraryName in iconLibraries
}

// 默认图标库
export const DEFAULT_ICON_LIBRARY = 'all'

// 切换图标库的辅助函数
export function switchIconLibrary(libraryName: string): IconLibraryConfig {
  const config = getIconLibraryConfig(libraryName)
  if (!config) {
    console.warn(`Unknown icon library: ${libraryName}, falling back to ${DEFAULT_ICON_LIBRARY}`)
    return iconLibraries[DEFAULT_ICON_LIBRARY]
  }
  return config
}
