import { icons, type LucideIcon } from 'lucide-react';

/**
 * 获取所有 Lucide React 图标列表
 * @returns 图标名称和组件的数组
 */
export const getAllLucideIcons = () => {
    return Object.entries(icons).map(([name, component]) => ({
        name,
        component: component as LucideIcon
    }));
};

/**
 * 根据名称获取 Lucide 图标组件
 * @param iconName 图标名称
 * @returns 图标组件或 null
 */
export const getLucideIcon = (iconName: string): LucideIcon | null => {
    return (icons[iconName as keyof typeof icons] as LucideIcon) || null;
};

/**
 * 常用图标分类
 */
export const ICON_CATEGORIES = {
    '常用': [
        'FolderKanban', 'Workflow', 'Settings', 'Users', 'Calendar',
        'Clock', 'Database', 'Server', 'Cloud', 'Package'
    ],
    '文件与文档': [
        'File', 'FileText', 'Folder', 'FolderOpen', 'Files',
        'FileJson', 'FileCode', 'FilePlus', 'FileEdit'
    ],
    '用户与团队': [
        'User', 'Users', 'UserPlus', 'UserCheck', 'UserCog',
        'Shield', 'ShieldCheck', 'Contact'
    ],
    '开发与代码': [
        'Code', 'Terminal', 'GitBranch', 'Github', 'GitFork',
        'GitCommit', 'GitPullRequest', 'Bug', 'Braces'
    ],
    '数据与存储': [
        'Database', 'HardDrive', 'Save', 'Download', 'Upload',
        'Archive', 'Package', 'Inbox', 'FolderSync'
    ],
    '网络与服务': [
        'Server', 'Cloud', 'CloudDownload', 'CloudUpload', 'Globe',
        'Wifi', 'Zap', 'Activity', 'TrendingUp'
    ],
    '时间与日历': [
        'Calendar', 'CalendarDays', 'Clock', 'Timer', 'AlarmClock',
        'History', 'CalendarCheck', 'CalendarPlus'
    ],
    '操作与控制': [
        'Play', 'Pause', 'Stop', 'RotateCw', 'RefreshCw',
        'Power', 'Settings', 'Sliders', 'ToggleLeft'
    ],
    '通知与提醒': [
        'Bell', 'BellRing', 'MessageSquare', 'Mail', 'Inbox',
        'AlertCircle', 'AlertTriangle', 'Info', 'CheckCircle'
    ],
    '编辑与格式': [
        'Edit', 'Edit2', 'Edit3', 'Pencil', 'Trash2',
        'Copy', 'Clipboard', 'Scissors', 'FileEdit'
    ],
    '导航与箭头': [
        'ArrowRight', 'ArrowLeft', 'ArrowUp', 'ArrowDown', 'ChevronRight',
        'ChevronLeft', 'ChevronUp', 'ChevronDown', 'Home', 'Menu'
    ],
    '状态与标记': [
        'Check', 'CheckCircle', 'CheckCircle2', 'X', 'XCircle',
        'AlertCircle', 'AlertTriangle', 'HelpCircle', 'Plus', 'Minus'
    ]
};

/**
 * 搜索图标
 * @param searchTerm 搜索关键词
 * @param category 分类（可选）
 * @returns 匹配的图标列表
 */
export const searchLucideIcons = (searchTerm: string, category?: string) => {
    const allIcons = getAllLucideIcons();
    
    let filtered = allIcons;
    
    // 按分类过滤
    if (category && category !== 'all') {
        const categoryIcons = ICON_CATEGORIES[category as keyof typeof ICON_CATEGORIES] || [];
        filtered = allIcons.filter(icon => categoryIcons.includes(icon.name));
    }
    
    // 按搜索词过滤
    if (searchTerm) {
        const search = searchTerm.toLowerCase();
        filtered = filtered.filter(icon => 
            icon.name.toLowerCase().includes(search)
        );
    }
    
    return filtered;
};

