import { RoutesAlias } from '../routesAlias'
import { AppRouteRecord } from '@/types/router'
import { BULK_PURCHASE_PERMISSIONS } from '@/config/constants/bulkPurchase'
import { NOTIFICATION_PERMISSIONS } from '@/config/constants/notification'

/**
 * 菜单列表、异步路由
 *
 * 支持两种模式:
 * 1. 前端静态配置 - 直接使用本文件中定义的路由配置
 * 2. 后端动态配置 - 后端返回菜单数据，前端解析生成路由
 *
 * 菜单标题（title）:
 * 可以是 i18n 的 key，也可以是字符串，比如：'用户列表'
 */
export const asyncRoutes: AppRouteRecord[] = [
  // 站内通知
  {
    path: '/notifications',
    name: 'Notifications',
    component: RoutesAlias.Home,
    meta: {
      title: '通知中心'
    },
    children: [
      {
        path: '',
        name: 'NotificationCenter',
        component: RoutesAlias.Notifications,
        meta: {
          title: '通知中心',
          permissions: [NOTIFICATION_PERMISSIONS.page],
          keepAlive: true
        }
      }
    ]
  },

  // 仪表台
  {
    name: 'Dashboard',
    path: '/dashboard',
    component: RoutesAlias.Home,
    meta: {
      title: 'menus.dashboard.title',
      icon: '&#xe721;'
    },
    children: [
      {
        path: 'console',
        name: 'Console',
        component: RoutesAlias.Dashboard,
        meta: {
          title: 'menus.dashboard.console',
          keepAlive: false,
          fixedTab: true
        }
      },
      {
        path: 'analysis',
        name: 'Analysis',
        component: RoutesAlias.Analysis,
        meta: {
          title: 'menus.dashboard.analysis',
          keepAlive: false
        }
      },
      {
        path: 'ecommerce',
        name: 'Ecommerce',
        component: RoutesAlias.Ecommerce,
        meta: {
          title: 'menus.dashboard.ecommerce',
          keepAlive: false
        }
      }
    ]
  },

  // 系统管理
  {
    path: '/system',
    name: 'System',
    component: RoutesAlias.Home,
    meta: {
      title: 'menus.system.title',
      icon: '&#xe7b9;',
      roles: ['R_SUPER', 'R_ADMIN']
    },
    children: [
      {
        path: 'role',
        name: 'Role',
        component: RoutesAlias.Role,
        meta: {
          title: 'menus.system.role',
          keepAlive: true,
          roles: ['R_SUPER']
        }
      },
      {
        path: 'permission',
        name: 'PermissionManagement',
        component: RoutesAlias.Permission,
        meta: {
          title: 'menus.system.permission',
          keepAlive: true,
          roles: ['R_SUPER']
        }
      },
      {
        path: 'carrier-management',
        name: 'CarrierManagement',
        component: RoutesAlias.CarrierManagement,
        meta: {
          title: 'menus.system.carrierManagement',
          keepAlive: true
        }
      },
      {
        path: 'user-center',
        name: 'UserCenter',
        component: RoutesAlias.UserCenter,
        meta: {
          title: 'menus.system.userCenter',
          isHide: true,
          keepAlive: true,
          isHideTab: true
        }
      }
    ]
  },

  // 套餐管理
  {
    path: '/package-management',
    name: 'PackageManagement',
    component: RoutesAlias.Home,
    meta: {
      title: 'menus.packageManagement.title',
      icon: '&#xe81a;'
    },
    children: [
      // 套餐系列
      {
        path: 'package-series',
        name: 'PackageSeries',
        component: RoutesAlias.PackageSeries,
        meta: {
          title: 'menus.packageManagement.packageSeries',
          keepAlive: true
        }
      },
      // 套餐系列详情
      {
        path: 'package-series/detail/:id',
        name: 'PackageSeriesDetail',
        component: RoutesAlias.PackageSeriesDetail,
        meta: {
          title: 'menus.packageManagement.packageSeriesDetail',
          isHide: true,
          keepAlive: false
        }
      },
      // 套餐列表
      {
        path: 'package-list',
        name: 'PackageList',
        component: RoutesAlias.PackageList,
        meta: {
          title: 'menus.packageManagement.packageList',
          keepAlive: true
        }
      },
      // 套餐列表详情
      {
        path: 'package-list/detail/:id',
        name: 'PackageDetail',
        component: RoutesAlias.PackageDetail,
        meta: {
          title: 'menus.packageManagement.packageDetail',
          isHide: true,
          keepAlive: false
        }
      },
      // 代理系列授权
      {
        path: 'series-grants',
        name: 'SeriesGrants',
        component: RoutesAlias.SeriesGrants,
        meta: {
          title: 'menus.packageManagement.seriesGrants',
          keepAlive: true
        }
      },
      // 系列授权详情
      {
        path: 'series-grants/detail/:id',
        name: 'SeriesGrantsDetail',
        component: RoutesAlias.SeriesGrantsDetail,
        meta: {
          title: 'menus.packageManagement.seriesGrantsDetail',
          isHide: true,
          keepAlive: false
        }
      },
      // 系列授权套餐列表
      {
        path: 'series-grants/packages/:id',
        name: 'SeriesGrantPackages',
        component: RoutesAlias.SeriesGrantPackages,
        meta: {
          title: 'menus.packageManagement.seriesGrantPackages',
          isHide: true,
          keepAlive: false
        }
      }
    ]
  },

  // 店铺管理
  {
    path: '/shop-management',
    name: 'ShopManagement',
    component: RoutesAlias.Home,
    meta: {
      title: 'menus.shopManagement.title',
      icon: '&#xe81a;'
    },
    children: [
      // 店铺列表
      {
        path: 'list',
        name: 'Shop',
        component: RoutesAlias.Shop,
        meta: {
          title: 'menus.shopManagement.shopList',
          keepAlive: true
        }
      }
    ]
  },

  // 账号管理
  {
    path: '/account-management',
    name: 'AccountManagement',
    component: RoutesAlias.Home,
    meta: {
      title: 'menus.accountManagement.title',
      icon: '&#xe7b9;'
    },
    children: [
      // 账号列表
      {
        path: 'account',
        name: 'Account',
        component: RoutesAlias.Account,
        meta: {
          title: 'menus.accountManagement.account',
          keepAlive: true
        }
      },
      // 企业客户
      {
        path: 'enterprise-customer',
        name: 'EnterpriseCustomer',
        component: RoutesAlias.EnterpriseCustomer,
        meta: {
          title: 'menus.accountManagement.enterpriseCustomer',
          keepAlive: true
        }
      },
      //企业客户账号列表和店铺账号列表共用
      {
        path: 'enterprise-customer/customer-accounts/:id',
        name: 'EnterpriseCustomerAccounts',
        component: RoutesAlias.EnterpriseCustomerAccounts,
        meta: {
          title: 'menus.accountManagement.enterpriseCustomerAccounts',
          isHide: true,
          keepAlive: false
        }
      }
    ]
  },

  // 资产管理
  {
    path: '/asset-management',
    name: 'AssetManagement',
    component: RoutesAlias.Home,
    meta: {
      title: 'menus.assetManagement.title',
      icon: '&#xe816;'
    },
    children: [
      // 资产信息
      {
        path: 'asset-information',
        name: 'AssetInformation',
        component: RoutesAlias.AssetInformation,
        meta: {
          title: 'menus.assetManagement.assetInformation',
          keepAlive: true
        }
      },
      // IoT卡管理
      {
        path: 'iot-card-management',
        name: 'StandaloneCardList',
        component: RoutesAlias.StandaloneCardList,
        meta: {
          title: 'menus.assetManagement.standaloneCardList',
          keepAlive: true
        }
      },
      // 设备管理
      {
        path: 'devices',
        name: 'DeviceList',
        component: RoutesAlias.DeviceList,
        meta: {
          title: 'menus.assetManagement.devices',
          keepAlive: true
        }
      },
      // 换货管理
      {
        path: 'exchange-management',
        name: 'ExchangeManagement',
        component: RoutesAlias.ExchangeManagement,
        meta: {
          title: 'menus.assetManagement.exchangeManagement',
          keepAlive: true
        }
      },
      // 换货详情
      {
        path: 'exchange-management/detail/:id',
        name: 'ExchangeDetail',
        component: RoutesAlias.ExchangeDetail,
        meta: {
          title: 'menus.assetManagement.exchangeDetail',
          isHide: true,
          keepAlive: false
        }
      },
      // 记录管理
      {
        path: 'record-management',
        name: 'RecordsManagement',
        component: '',
        meta: {
          title: 'menus.assetManagement.recordsManagement',
          keepAlive: true
        },
        children: [
          // 资产分配
          {
            path: 'asset-assign',
            name: 'AssetAssign',
            component: RoutesAlias.AssetAssign,
            meta: {
              title: 'menus.assetManagement.assetAssign',
              keepAlive: true
            }
          },
          // 授权记录
          {
            path: 'authorization-records',
            name: 'AuthorizationRecords',
            component: RoutesAlias.AuthorizationRecords,
            meta: {
              title: 'menus.assetManagement.authorizationRecords',
              keepAlive: true
            }
          }
        ]
      },
      // 分配记录详情（放在 asset-management 层级）
      {
        path: 'record-management/asset-assign/detail/:id',
        name: 'AssetAssignDetail',
        component: RoutesAlias.AssetAssignDetail,
        meta: {
          title: 'menus.assetManagement.assetAssignDetail',
          isHide: true,
          keepAlive: false
        }
      },
      // 授权记录详情（放在 asset-management 层级）
      {
        path: 'record-management/authorization-records/detail/:id',
        name: 'AuthorizationRecordDetail',
        component: RoutesAlias.AuthorizationRecordDetail,
        meta: {
          title: 'menus.assetManagement.authorizationRecordDetail',
          isHide: true,
          keepAlive: false
        }
      },
      // 任务管理
      {
        path: 'task-management',
        name: 'TaskManagement',
        component: '',
        meta: {
          title: 'menus.assetManagement.taskManagement',
          keepAlive: true
        },
        children: [
          // IoT卡任务
          {
            path: 'iot-card-task',
            name: 'IotCardTask',
            component: RoutesAlias.IotCardTask,
            meta: {
              title: 'menus.assetManagement.iotCardTask',
              keepAlive: true
            }
          },
          // 设备任务
          {
            path: 'device-task',
            name: 'DeviceTask',
            component: RoutesAlias.DeviceTask,
            meta: {
              title: 'menus.assetManagement.deviceTask',
              keepAlive: true
            }
          },
          // 订单套餐批量作废任务
          {
            path: 'order-package-invalidate-task',
            name: 'OrderPackageInvalidateTask',
            component: RoutesAlias.OrderPackageInvalidateTask,
            meta: {
              title: 'menus.assetManagement.orderPackageInvalidateTask',
              keepAlive: true
            }
          }
        ]
      },
      // 订单套餐作废任务详情
      {
        path: 'task-management/order-package-invalidate-task/detail',
        name: 'OrderPackageInvalidateTaskDetail',
        component: RoutesAlias.OrderPackageInvalidateTaskDetail,
        meta: {
          title: 'menus.assetManagement.orderPackageInvalidateTaskDetail',
          isHide: true,
          keepAlive: false
        }
      },
      // 任务详情（放在 asset-management 层级）
      {
        path: 'task-management/task-detail',
        name: 'TaskDetail',
        component: RoutesAlias.TaskDetail,
        meta: {
          title: 'menus.assetManagement.taskDetail',
          isHide: true,
          keepAlive: false
        }
      },
      // 导出管理
      {
        path: 'export-task-management',
        name: 'ExportTaskManagement',
        component: '',
        meta: {
          title: 'menus.assetManagement.exportTaskManagement',
          keepAlive: true
        },
        children: [
          {
            path: 'export-device',
            name: 'ExportDeviceTaskList',
            component: RoutesAlias.ExportDeviceTaskList,
            meta: {
              title: 'menus.assetManagement.exportDevice',
              exportTaskScene: 'device',
              keepAlive: true
            }
          },
          {
            path: 'export-iot-card',
            name: 'ExportIotCardTaskList',
            component: RoutesAlias.ExportIotCardTaskList,
            meta: {
              title: 'menus.assetManagement.exportIotCard',
              exportTaskScene: 'iot_card',
              keepAlive: true
            }
          },
          {
            path: 'export-order',
            name: 'ExportOrderTaskList',
            component: RoutesAlias.ExportOrderTaskList,
            meta: {
              title: 'menus.assetManagement.exportOrder',
              exportTaskScene: 'order',
              keepAlive: true
            }
          },
          {
            path: 'export-task-detail',
            name: 'ExportTaskDetail',
            component: RoutesAlias.ExportTaskDetail,
            meta: {
              title: 'menus.assetManagement.exportTaskDetail',
              isHide: true,
              keepAlive: false
            }
          }
        ]
      }
    ]
  },

  // 订单管理
  {
    path: '/order-management',
    name: 'OrderManagement',
    component: RoutesAlias.Home,
    meta: {
      title: 'menus.orderManagement.title',
      icon: '&#xe7ae;'
    },
    children: [
      // 订单列表
      {
        path: 'order-list',
        name: 'OrderList',
        component: RoutesAlias.OrderList,
        meta: {
          title: 'menus.orderManagement.orderList',
          keepAlive: true
        }
      },
      // 订单详情
      {
        path: 'order-list/detail/:id',
        name: 'OrderDetail',
        component: RoutesAlias.OrderDetail,
        meta: {
          title: 'menus.orderManagement.orderDetail',
          isHide: true,
          keepAlive: false
        }
      },
      // 批量订购
      {
        path: 'bulk-purchase',
        name: 'BulkPurchase',
        component: RoutesAlias.BulkPurchase,
        meta: {
          title: '批量订购套餐',
          permissions: [BULK_PURCHASE_PERMISSIONS.page],
          keepAlive: true
        }
      }
    ]
  },

  // 财务管理
  {
    path: '/finance',
    name: 'FinanceManagement',
    component: RoutesAlias.Home,
    meta: {
      title: 'menus.financialManagement.title',
      icon: '&#xe816;'
    },
    children: [
      // 代理充值
      {
        path: 'agent-recharge',
        name: 'AgentRecharge',
        component: RoutesAlias.AgentRecharge,
        meta: {
          title: 'menus.financialManagement.agentRecharge',
          keepAlive: true
        }
      },
      // 充值详情
      {
        path: 'agent-recharge/detail/:id',
        name: 'AgentRechargeDetailRoute',
        component: RoutesAlias.AgentRechargeDetail,
        meta: {
          title: 'menus.financialManagement.agentRechargeDetail',
          isHide: true,
          keepAlive: false
        }
      },
      // 退款管理
      {
        path: 'refund',
        name: 'RefundManagement',
        component: RoutesAlias.RefundManagement,
        meta: {
          title: 'menus.financialManagement.refundManagement',
          keepAlive: true
        }
      },
      // 退款详情
      {
        path: 'refund/detail/:id',
        name: 'RefundDetailRoute',
        component: RoutesAlias.RefundDetail,
        meta: {
          title: 'menus.financialManagement.refundDetail',
          isHide: true,
          keepAlive: false
        }
      }
    ]
  },

  // 佣金管理
  {
    path: '/commission',
    name: 'CommissionManagement',
    component: RoutesAlias.Home,
    meta: {
      title: 'menus.commission.title',
      icon: '&#xe816;'
    },
    children: [
      // 提现审批
      {
        path: 'withdrawal-approval',
        name: 'WithdrawalApproval',
        component: RoutesAlias.WithdrawalApproval,
        meta: {
          title: 'menus.commission.withdrawal',
          keepAlive: true,
          roles: ['R_SUPER', 'R_ADMIN']
        }
      },
      // 我的佣金
      {
        path: 'my-commission',
        name: 'MyCommission',
        component: RoutesAlias.MyCommission,
        meta: {
          title: 'menus.commission.myCommission',
          keepAlive: true,
          roles: ['R_AGENT']
        }
      },
      // 代理商资金概况
      {
        path: 'agent-fund-overview',
        name: 'AgentFundOverview',
        component: RoutesAlias.AgentFundOverview,
        meta: {
          title: 'menus.commission.agentCommission',
          keepAlive: true,
          roles: ['R_SUPER', 'R_ADMIN']
        }
      }
    ]
  },

  // 设置管理
  {
    path: '/settings',
    name: 'Settings',
    component: RoutesAlias.Home,
    meta: {
      title: 'menus.settings.title',
      icon: '&#xe715;'
    },
    children: [
      // 支付设置
      {
        path: 'payment-settings',
        name: 'PaymentSettings',
        component: RoutesAlias.PaymentSettings,
        meta: {
          title: 'menus.settings.paymentSettings',
          keepAlive: true
        }
      },
      // 提现配置
      {
        path: 'withdrawal-settings',
        name: 'WithdrawalSettings',
        component: RoutesAlias.WithdrawalSettings,
        meta: {
          title: 'menus.settings.withdrawalSettings',
          keepAlive: true,
          roles: ['R_SUPER', 'R_ADMIN']
        }
      },
      // 支付设置详情
      {
        path: 'payment-settings/detail/:id',
        name: 'PaymentSettingsDetailRoute',
        component: RoutesAlias.PaymentSettingsDetail,
        meta: {
          title: 'menus.settings.detailsOfPaymentConfiguration',
          isHide: true,
          keepAlive: false
        }
      },
      // 操作密码设置
      {
        path: 'operation-password',
        name: 'OperationPasswordSettings',
        component: RoutesAlias.OperationPasswordSettings,
        meta: {
          title: 'menus.settings.passwordSettings',
          keepAlive: true,
          roles: ['R_SUPER']
        }
      }
    ]
  },

  // 轮询管理
  {
    path: '/polling-management',
    name: 'PollingManagement',
    component: RoutesAlias.Home,
    meta: {
      title: '轮询管理',
      icon: '&#xe68a;'
    },
    children: [
      // 数据清理
      {
        path: 'data-cleanup',
        name: 'DataCleanup',
        component: RoutesAlias.DataCleanup,
        meta: {
          title: '数据清理',
          keepAlive: true
        }
      },
      // 告警规则
      {
        path: 'alert-rules',
        name: 'AlertRules',
        component: RoutesAlias.AlertRules,
        meta: {
          title: '告警规则',
          keepAlive: true
        }
      },
      // 告警历史
      {
        path: 'alert-history',
        name: 'AlertHistory',
        component: RoutesAlias.AlertHistory,
        meta: {
          title: '告警历史',
          keepAlive: true
        }
      },
      // 并发控制
      {
        path: 'concurrency',
        name: 'PollingConcurrency',
        component: RoutesAlias.PollingConcurrency,
        meta: {
          title: '并发控制',
          keepAlive: true
        }
      },
      // 轮询配置
      {
        path: 'config',
        name: 'PollingConfig',
        component: RoutesAlias.PollingConfig,
        meta: {
          title: '轮询配置',
          keepAlive: true
        }
      },
      // 手动触发
      {
        path: 'manual-trigger',
        name: 'ManualTrigger',
        component: RoutesAlias.ManualTrigger,
        meta: {
          title: '手动触发',
          keepAlive: true
        }
      },
      // 轮询监控
      {
        path: 'monitor',
        name: 'PollingMonitor',
        component: RoutesAlias.PollingMonitor,
        meta: {
          title: '轮询监控',
          keepAlive: true
        }
      }
    ]
  }

  // 组件中心
  // {
  //   path: '/widgets',
  //   name: 'Widgets',
  //   component: RoutesAlias.Home,
  //   meta: {
  //     title: 'menus.widgets.title',
  //     icon: '&#xe81a;'
  //   },
  //   children: [
  //     {
  //       path: 'wang-editor',
  //       name: 'WangEditor',
  //       component: RoutesAlias.WangEditor,
  //       meta: {
  //         title: 'menus.widgets.wangEditor',
  //         keepAlive: true
  //       }
  //     },
  //     {
  //       path: 'watermark',
  //       name: 'Watermark',
  //       component: RoutesAlias.Watermark,
  //       meta: {
  //         title: 'menus.widgets.watermark',
  //         keepAlive: true
  //       }
  //     },
  //     {
  //       path: 'context-menu',
  //       name: 'ContextMenu',
  //       component: RoutesAlias.ContextMenu,
  //       meta: {
  //         title: 'menus.widgets.contextMenu',
  //         keepAlive: true
  //       }
  //     },
  //     {
  //       path: 'qrcode',
  //       name: 'Qrcode',
  //       component: RoutesAlias.Qrcode,
  //       meta: {
  //         title: 'menus.widgets.qrcode',
  //         keepAlive: true
  //       }
  //     },
  //     {
  //       path: 'drag',
  //       name: 'Drag',
  //       component: RoutesAlias.Drag,
  //       meta: {
  //         title: 'menus.widgets.drag',
  //         keepAlive: true
  //       }
  //     }
  //   ]
  // },

  // 模板中心
  // {
  //   path: '/template',
  //   name: 'Template',
  //   component: RoutesAlias.Home,
  //   meta: {
  //     title: 'menus.template.title',
  //     icon: '&#xe860;'
  //   },
  //   children: [
  //     {
  //       path: 'charts',
  //       name: 'Charts',
  //       component: RoutesAlias.Charts,
  //       meta: {
  //         title: 'menus.template.charts',
  //         keepAlive: false
  //       }
  //     },
  //     {
  //       path: 'map',
  //       name: 'Map',
  //       component: RoutesAlias.Map,
  //       meta: {
  //         title: 'menus.template.map',
  //         keepAlive: true
  //       }
  //     },
  //     {
  //       path: 'calendar',
  //       name: 'Calendar',
  //       component: RoutesAlias.Calendar,
  //       meta: {
  //         title: 'menus.template.calendar',
  //         keepAlive: true
  //       }
  //     }
  //   ]
  // },
]
