import fs from 'fs';
import icons from '@vicons/tabler';

const iconNames = Object.keys(icons);
console.log(`Total icons: ${iconNames.length}`);

// 生成导入语句
const imports = iconNames.map(name => name).join(',\n  ');

// 生成映射对象
const mappings = iconNames.map(name => {
  const displayName = name.replace(/^Icon/, '') + 'Outlined';
  return `  ${displayName}: ${name}`;
}).join(',\n');

const output = `import { 
  ${imports}
} from '@vicons/tabler'
import type { Component } from 'vue'

// 静态图标映射 - 所有Tabler图标
const tablerIconMap: Record<string, Component> = {
${mappings}
}

// 获取图标组件
export function getIconComponent(name?: string): Component | null {
  if (!name) return null
  return tablerIconMap[name] || null
}

// 获取所有可用的图标名称
export function getAvailableIcons(): string[] {
  return Object.keys(tablerIconMap)
}

// 图标分类定义
export const iconCategories = {
  common: {
    name: '常用',
    icons: [
      { name: 'DashboardOutlined', label: '仪表板', keywords: ['dashboard', '控制台'] },
      { name: 'HomeOutlined', label: '首页', keywords: ['home', '首页'] },
      { name: 'SettingOutlined', label: '设置', keywords: ['setting', '设置'] },
      { name: 'MenuOutlined', label: '菜单', keywords: ['menu', '菜单'] },
      { name: 'UserOutlined', label: '用户', keywords: ['user', '用户'] },
      { name: 'FileOutlined', label: '文件', keywords: ['file', '文件'] },
      { name: 'FolderOutlined', label: '文件夹', keywords: ['folder', '文件夹'] },
      { name: 'SearchOutlined', label: '搜索', keywords: ['search', '搜索'] }
    ]
  },
  user: {
    name: '用户',
    icons: [
      { name: 'UserOutlined', label: '用户', keywords: ['user', '用户'] },
      { name: 'UsersOutlined', label: '团队', keywords: ['team', '团队'] },
      { name: 'LockOutlined', label: '锁定', keywords: ['lock', '锁定'] },
      { name: 'KeyOutlined', label: '钥匙', keywords: ['key', '钥匙'] },
      { name: 'ShieldOutlined', label: '安全', keywords: ['safety', '安全'] },
      { name: 'CrownOutlined', label: '皇冠', keywords: ['crown', '皇冠'] },
      { name: 'TrophyOutlined', label: '奖杯', keywords: ['trophy', '奖杯'] },
      { name: 'GiftOutlined', label: '礼物', keywords: ['gift', '礼物'] }
    ]
  },
  file: {
    name: '文件',
    icons: [
      { name: 'FileOutlined', label: '文件', keywords: ['file', '文件'] },
      { name: 'FolderOutlined', label: '文件夹', keywords: ['folder', '文件夹'] },
      { name: 'FolderOpenOutlined', label: '打开文件夹', keywords: ['folder-open', '打开文件夹'] },
      { name: 'DownloadOutlined', label: '下载', keywords: ['download', '下载'] },
      { name: 'UploadOutlined', label: '上传', keywords: ['upload', '上传'] },
      { name: 'ExportOutlined', label: '导出', keywords: ['export', '导出'] },
      { name: 'ImportOutlined', label: '导入', keywords: ['import', '导入'] },
      { name: 'PrinterOutlined', label: '打印', keywords: ['printer', '打印'] }
    ]
  },
  data: {
    name: '数据',
    icons: [
      { name: 'BarChartOutlined', label: '柱状图', keywords: ['bar-chart', '柱状图'] },
      { name: 'PieChartOutlined', label: '饼图', keywords: ['pie-chart', '饼图'] },
      { name: 'LineChartOutlined', label: '折线图', keywords: ['line-chart', '折线图'] },
      { name: 'TableOutlined', label: '表格', keywords: ['table', '表格'] },
      { name: 'DatabaseOutlined', label: '数据库', keywords: ['database', '数据库'] },
      { name: 'CloudOutlined', label: '云', keywords: ['cloud', '云'] },
      { name: 'ApiOutlined', label: 'API', keywords: ['api', '接口'] },
      { name: 'MonitorOutlined', label: '监控', keywords: ['monitor', '监控'] }
    ]
  },
  system: {
    name: '系统',
    icons: [
      { name: 'ToolOutlined', label: '工具', keywords: ['tool', '工具'] },
      { name: 'BugOutlined', label: 'Bug', keywords: ['bug', '错误'] },
      { name: 'CodeOutlined', label: '代码', keywords: ['code', '代码'] },
      { name: 'ApiOutlined', label: 'API', keywords: ['api', '接口'] },
      { name: 'ExperimentOutlined', label: '实验', keywords: ['experiment', '实验'] },
      { name: 'BulbOutlined', label: '灯泡', keywords: ['bulb', '灯泡'] },
      { name: 'SettingOutlined', label: '设置', keywords: ['setting', '设置'] },
      { name: 'ControlOutlined', label: '控制', keywords: ['control', '控制'] }
    ]
  },
  media: {
    name: '媒体',
    icons: [
      { name: 'CameraOutlined', label: '相机', keywords: ['camera', '相机'] },
      { name: 'PictureOutlined', label: '图片', keywords: ['picture', '图片'] },
      { name: 'VideoCameraOutlined', label: '视频', keywords: ['video', '视频'] },
      { name: 'AudioOutlined', label: '音频', keywords: ['audio', '音频'] },
      { name: 'PlayCircleOutlined', label: '播放', keywords: ['play', '播放'] },
      { name: 'PauseCircleOutlined', label: '暂停', keywords: ['pause', '暂停'] },
      { name: 'StopOutlined', label: '停止', keywords: ['stop', '停止'] },
      { name: 'SoundOutlined', label: '声音', keywords: ['sound', '声音'] }
    ]
  },
  navigation: {
    name: '导航',
    icons: [
      { name: 'ArrowUpOutlined', label: '上箭头', keywords: ['arrow-up', '上箭头'] },
      { name: 'ArrowDownOutlined', label: '下箭头', keywords: ['arrow-down', '下箭头'] },
      { name: 'ArrowLeftOutlined', label: '左箭头', keywords: ['arrow-left', '左箭头'] },
      { name: 'ArrowRightOutlined', label: '右箭头', keywords: ['arrow-right', '右箭头'] },
      { name: 'UpOutlined', label: '向上', keywords: ['up', '向上'] },
      { name: 'DownOutlined', label: '向下', keywords: ['down', '向下'] },
      { name: 'LeftOutlined', label: '向左', keywords: ['left', '向左'] },
      { name: 'RightOutlined', label: '向右', keywords: ['right', '向右'] }
    ]
  },
  action: {
    name: '操作',
    icons: [
      { name: 'EditOutlined', label: '编辑', keywords: ['edit', '编辑'] },
      { name: 'DeleteOutlined', label: '删除', keywords: ['delete', '删除'] },
      { name: 'PlusOutlined', label: '添加', keywords: ['plus', '添加'] },
      { name: 'MinusOutlined', label: '减少', keywords: ['minus', '减少'] },
      { name: 'CheckOutlined', label: '确认', keywords: ['check', '确认'] },
      { name: 'CloseOutlined', label: '关闭', keywords: ['close', '关闭'] },
      { name: 'ReloadOutlined', label: '刷新', keywords: ['reload', '刷新'] },
      { name: 'SyncOutlined', label: '同步', keywords: ['sync', '同步'] }
    ]
  }
}

// 图标选项接口
export interface IconOption {
  name: string
  label: string
  category: string
  keywords?: string[]
}

// 获取所有图标选项
export function getAllIconOptions(): IconOption[] {
  const allIcons: IconOption[] = []
  
  Object.entries(iconCategories).forEach(([, category]) => {
    category.icons.forEach(icon => {
      allIcons.push({
        name: icon.name,
        label: icon.label,
        category: category.name,
        keywords: icon.keywords
      })
    })
  })
  
  return allIcons
}

// 搜索图标
export function searchIcons(query: string): IconOption[] {
  const allIcons = getAllIconOptions()
  const lowerQuery = query.toLowerCase()
  
  return allIcons.filter(icon => 
    icon.name.toLowerCase().includes(lowerQuery) ||
    icon.label.toLowerCase().includes(lowerQuery) ||
    icon.keywords?.some(keyword => keyword.toLowerCase().includes(lowerQuery))
  )
}`;

fs.writeFileSync('/tmp/tabler-icons-full.ts', output);
console.log('Generated full tabler-icons.ts file');
