import request from '@/utils/request'
import { ModuleKey } from '@/enums/ModuleEnum'

export interface PortalMenuItem {
  id: string
  title: string
  path: string
  icon?: string
  children?: PortalMenuItem[]
}

export interface PortalModuleMenu {
  module: ModuleKey
  commonMenus: PortalMenuItem[]
  moduleMenus: PortalMenuItem[]
}

/**
 * 新门户菜单接口（后端待提供）
 * 约定：返回“模块 + 菜单树”聚合结构，替代旧查询菜单接口
 */
export const fetchPortalMenus = () => {
  return request({
    url: '/sys/portal/menu/tree',
    method: 'post',
  })
}

/**
 * 接口未就绪时的本地 mock，优先对齐旧版菜单结构与当前已挂路由。
 */
export const getPortalMenusMock = (): PortalModuleMenu[] => ([
  {
    module: ModuleKey.HOME,
    commonMenus: [
      { id: 'home-dashboard', title: '首页', path: '/home/dashboard', icon: 'dashboard' },
      { id: 'home-otr-task', title: '任务管理', path: '/otr/task/list', icon: 'edit' },
      { id: 'home-otr-summary', title: '我的简报', path: '/otr/summary/list', icon: 'documentation' },
      { id: 'home-sales-index', title: '销售首页', path: '/index', icon: 'chart' },
    ],
    moduleMenus: [],
  },
  {
    module: ModuleKey.OTR,
    commonMenus: [],
    moduleMenus: [
      {
        id: 'otr-target',
        title: '目标',
        path: '/otr/target',
        icon: 'guide',
        children: [
          { id: 'otr-target-company', title: '公司目标', path: '/otr/target/company', icon: 'office-building' },
          { id: 'otr-target-depart', title: '部门目标', path: '/otr/target/depart', icon: 'files' },
          { id: 'otr-target-mine', title: '我的目标', path: '/otr/target/mine', icon: 'user' },
          { id: 'otr-task-list', title: '任务管理', path: '/otr/task/list', icon: 'edit' },
          { id: 'otr-award-list', title: '奖励审批', path: '/otr/award/list', icon: 'star' },
          { id: 'otr-target-report', title: '目标报告', path: '/otr/target/report', icon: 'data-analysis' },
        ],
      },
      {
        id: 'otr-summary',
        title: '简报',
        path: '/otr/summary',
        icon: 'documentation',
        children: [
          { id: 'otr-summary-list', title: '我的简报', path: '/otr/summary/list', icon: 'document' },
          { id: 'otr-summary-member', title: '成员简报', path: '/otr/summary/member', icon: 'peoples' },
          { id: 'otr-summary-create', title: '新建简报', path: '/otr/summary/create', icon: 'edit-pen' },
          { id: 'otr-summary-share', title: '心得分享', path: '/otr/summary/share', icon: 'chat-dot-round' },
          { id: 'otr-summary-draft', title: '草稿箱', path: '/otr/summary/draft', icon: 'tickets' },
          { id: 'otr-summary-settings', title: '简报设置', path: '/otr/summary/settings', icon: 'setting' },
          { id: 'otr-summary-remind-task', title: '简报提醒', path: '/otr/summary/remind-task', icon: 'bell' },
        ],
      },
      {
        id: 'otr-effect',
        title: '绩效',
        path: '/otr/effect',
        icon: 'chart',
        children: [
          { id: 'otr-effect-mine', title: '我的绩效', path: '/otr/effect/mine', icon: 'user' },
          { id: 'otr-effect-backlog', title: '我的待办', path: '/otr/effect/backlog', icon: 'list' },
          { id: 'otr-effect-manage', title: '绩效管理', path: '/otr/effect/manage', icon: 'histogram' },
          { id: 'otr-effect-setting', title: '绩效设置', path: '/otr/effect/setting', icon: 'setting' },
        ],
      },
      {
        id: 'otr-notice',
        title: '通知',
        path: '/otr/notice',
        icon: 'message',
        children: [
          { id: 'otr-notice-list', title: '内部公告', path: '/otr/summary/announcement', icon: 'notification' },
          { id: 'otr-notice-system', title: '系统通知', path: '/otr/notice/list', icon: 'message' },
        ],
      },
      {
        id: 'otr-report',
        title: '报告',
        path: '/otr/report',
        icon: 'data-analysis',
        children: [
          { id: 'otr-report-person', title: '人员报告', path: '/otr/report/person', icon: 'data-line' },
        ],
      },
      {
        id: 'otr-ai',
        title: 'AI工具',
        path: '/otr/ai',
        icon: 'magic-stick',
        children: [
          { id: 'otr-ai-add', title: 'AI 工具', path: '/otr/ai/add', icon: 'magic-stick' },
        ],
      },
    ],
  },
  {
    module: ModuleKey.SALES,
    commonMenus: [],
    moduleMenus: [
      { id: 'sales-index', title: '销售首页', path: '/index', icon: 'dashboard' },
      { id: 'sales-clue-add', title: '新增线索', path: '/clue/add', icon: 'edit' },
      { id: 'sales-customer-add', title: '创建客户', path: '/customer/addCustomer', icon: 'user' },
    ],
  },
  { module: ModuleKey.PROJECT, commonMenus: [], moduleMenus: [] },
  { module: ModuleKey.SALARY, commonMenus: [], moduleMenus: [] },
  { module: ModuleKey.WEBSITE, commonMenus: [], moduleMenus: [] },
])


