import {
    BarChartOutlined,
    FileTextOutlined,
    EditOutlined,
    SettingOutlined,
    DashboardOutlined,
    BankOutlined,
    UserOutlined,
    StockOutlined,
    LineChartOutlined,
} from '@ant-design/icons';
import type { ReactNode } from 'react';

/**
 * 路由菜单配置项
 */
export interface RouteMenuConfig {
    /** 路由路径 */
    path: string;
    /** 菜单键值（通常与 path 相同） */
    key: string;
    /** 菜单图标 */
    icon: ReactNode;
    /** 菜单标签 */
    label: string;
    /** 页面标题 */
    title: string;
    /** 页面副标题 */
    subtitle: string;
    /** 菜单分组：'main' 主要功能，'admin' 管理员功能 */
    group: 'main' | 'admin';
    /** 是否需要管理员权限 */
    requireAdmin?: boolean;
}

/**
 * 路由菜单配置列表
 */
export const routeMenuConfig: RouteMenuConfig[] = [
    {
        path: '/assets',
        key: '/assets',
        icon: <BarChartOutlined />,
        label: '资产账户',
        title: '资产账户',
        subtitle: '买股票就是买公司',
        group: 'main',
    },
    {
        path: '/plans',
        key: '/plans',
        icon: <FileTextOutlined />,
        label: '交易计划',
        title: '交易计划',
        subtitle: '计划你的交易，交易你的计划',
        group: 'main',
    },
    {
        path: '/review',
        key: '/review',
        icon: <EditOutlined />,
        label: '投资复盘',
        title: '投资复盘',
        subtitle: '回顾过去是为了更好应对将来',
        group: 'main',
    },
    {
        path: '/user-info',
        key: '/user-info',
        icon: <UserOutlined />,
        label: '个人资料',
        title: '个人资料',
        subtitle: '查看和编辑个人信息',
        group: 'main',
    },
    {
        path: '/user',
        key: '/user',
        icon: <UserOutlined />,
        label: '用户管理',
        title: '用户管理',
        subtitle: '管理用户信息',
        group: 'admin',
        requireAdmin: true,
    },
    {
        path: '/broker',
        key: '/broker',
        icon: <BankOutlined />,
        label: '券商管理',
        title: '券商管理',
        subtitle: '管理券商信息',
        group: 'admin',
        requireAdmin: true,
    },
    {
        path: '/stock-info',
        key: '/stock-info',
        icon: <StockOutlined />,
        label: '股票信息',
        title: '股票信息',
        subtitle: '管理股票基本信息',
        group: 'admin',
        requireAdmin: true,
    },
    {
        path: '/stock-daily-price',
        key: '/stock-daily-price',
        icon: <LineChartOutlined />,
        label: '股票价格',
        title: '股票价格',
        subtitle: '查看股票每日价格数据',
        group: 'admin',
        requireAdmin: true,
    },
    {
        path: '/seo',
        key: '/seo',
        icon: <SettingOutlined />,
        label: 'SEO配置',
        title: 'SEO配置',
        subtitle: '优化搜索引擎可见性',
        group: 'admin',
        requireAdmin: true,
    },
    {
        path: '/analytics',
        key: '/analytics',
        icon: <DashboardOutlined />,
        label: '数据统计',
        title: '数据统计',
        subtitle: '了解用户行为与系统数据',
        group: 'admin',
        requireAdmin: true,
    },
];

/**
 * 根据路径获取页面标题信息
 */
export const getPageInfo = (path: string): { title: string; subtitle: string } => {
    // 处理根路径
    if (path === '/' || path === '') {
        const defaultRoute = routeMenuConfig.find((item) => item.path === '/assets');
        return defaultRoute
            ? { title: defaultRoute.title, subtitle: defaultRoute.subtitle }
            : { title: '资产账户', subtitle: '买股票就是买公司' };
    }

    const config = routeMenuConfig.find((item) => item.path === path);
    return config
        ? { title: config.title, subtitle: config.subtitle }
        : { title: '资产账户', subtitle: '买股票就是买公司' };
};

/**
 * 获取主要功能菜单项
 */
export const getMainMenuItems = () => {
    return routeMenuConfig.filter((item) => item.group === 'main');
};

/**
 * 获取管理员功能菜单项
 */
export const getAdminMenuItems = () => {
    return routeMenuConfig.filter((item) => item.group === 'admin' && item.requireAdmin);
};

/**
 * 页面标题映射（用于向后兼容）
 */
export const pageTitles: Record<string, { title: string; subtitle: string }> = (() => {
    const titles: Record<string, { title: string; subtitle: string }> = {
        '/': getPageInfo('/assets'),
    };

    routeMenuConfig.forEach((config) => {
        titles[config.path] = {
            title: config.title,
            subtitle: config.subtitle,
        };
    });

    return titles;
})();
