export type AppMode = 'user' | 'admin'
export type LoginType = 'guest' | 'staff'

export interface MenuItem {
  key: string
  title: string
  path: string
  icon?: string
  children?: MenuItem[]
}

/** 前台频道（功能入口）——路径指向 content 分包（单层，勿重复前缀） */
export const PUBLIC_MENUS: MenuItem[] = [
  { key: 'blog', title: '思考', path: '/subPackages/content/pages/blog/index', icon: 'edit' },
  { key: 'columns', title: '专栏', path: '/subPackages/content/pages/columns/index', icon: 'book' },
  { key: 'works', title: '作品', path: '/subPackages/content/pages/works/index', icon: 'image' },
  { key: 'videos', title: '视频', path: '/subPackages/content/pages/videos/index', icon: 'video-camera' },
  { key: 'snippets', title: '代码', path: '/subPackages/content/pages/snippets/index', icon: 'code' },
  { key: 'about', title: '关于', path: '/subPackages/content/pages/about/index', icon: 'user' },
  { key: 'services', title: '合作', path: '/subPackages/content/pages/services/index', icon: 'headset' },
]

/** 后台菜单树（功能入口）；icon 须为 @wot-ui v2 有效名 */
export const ADMIN_MENUS: MenuItem[] = [
  { key: 'dashboard', title: '概览', path: '/subPackages/admin/pages/dashboard/index', icon: 'dashboard' },
  { key: 'analytics', title: '数据分析', path: '/subPackages/admin/pages/analytics/index', icon: 'mind-mapping' },
  {
    key: 'content',
    title: '内容管理',
    path: '',
    icon: 'book',
    children: [
      { key: 'posts', title: '文章管理', path: '/subPackages/admin/pages/posts/list', icon: 'edit' },
      { key: 'categories', title: '分类管理', path: '/subPackages/admin/pages/resource/list?resource=categories', icon: 'list' },
      { key: 'columns', title: '专栏管理', path: '/subPackages/admin/pages/resource/list?resource=columns', icon: 'book' },
      { key: 'works', title: '作品管理', path: '/subPackages/admin/pages/works/list', icon: 'image' },
      { key: 'video-categories', title: '视频分类', path: '/subPackages/admin/pages/resource/list?resource=video-categories', icon: 'list' },
      { key: 'video-albums', title: '视频专辑', path: '/subPackages/admin/pages/resource/list?resource=video-albums', icon: 'folder' },
      { key: 'videos', title: '视频列表', path: '/subPackages/admin/pages/videos/list', icon: 'video-camera' },
      { key: 'snippets', title: '代码片段', path: '/subPackages/admin/pages/resource/list?resource=snippets', icon: 'code' },
      { key: 'code-types', title: '代码分类', path: '/subPackages/admin/pages/resource/list?resource=code-types', icon: 'code-block' },
      { key: 'tags', title: '标签管理', path: '/subPackages/admin/pages/resource/list?resource=tags', icon: 'apps' },
    ],
  },
  {
    key: 'pages',
    title: '页面配置',
    path: '',
    icon: 'application',
    children: [
      { key: 'about', title: '关于页面', path: '/subPackages/admin/pages/about/index', icon: 'user' },
      { key: 'testimonials', title: '客户评价', path: '/subPackages/admin/pages/resource/list?resource=testimonials', icon: 'message' },
      { key: 'partners', title: '合作伙伴', path: '/subPackages/admin/pages/resource/list?resource=partners', icon: 'user-group' },
    ],
  },
  {
    key: 'business',
    title: '业务中心',
    path: '',
    icon: 'email',
    children: [
      { key: 'inquiries', title: '合作咨询', path: '/subPackages/admin/pages/inquiries/list', icon: 'email' },
      { key: 'email-suffixes', title: '邮箱配置', path: '/subPackages/admin/pages/resource/list?resource=email-suffixes', icon: 'settings' },
    ],
  },
  {
    key: 'users',
    title: '用户权限',
    path: '',
    icon: 'user-group',
    children: [
      { key: 'users', title: '用户管理', path: '/subPackages/admin/pages/users/list', icon: 'user' },
      { key: 'roles', title: '角色管理', path: '/subPackages/admin/pages/resource/list?resource=roles', icon: 'lock' },
    ],
  },
  {
    key: 'attachments',
    title: '附件管理',
    path: '',
    icon: 'folder',
    children: [
      { key: 'attachments', title: '附件库', path: '/subPackages/admin/pages/attachments/index', icon: 'file' },
      { key: 'attachment-categories', title: '附件分类', path: '/subPackages/admin/pages/resource/list?resource=attachment-categories', icon: 'folder-add' },
      { key: 'oss-configs', title: 'OSS配置', path: '/subPackages/admin/pages/oss-configs/index', icon: 'cloud' },
    ],
  },
  {
    key: 'system',
    title: '系统设置',
    path: '',
    icon: 'settings',
    children: [
      { key: 'settings', title: '全局配置', path: '/subPackages/admin/pages/settings/index', icon: 'settings' },
      { key: 'ppt-templates', title: 'PPT 模板', path: '/subPackages/admin/pages/resource/list?resource=ppt-templates', icon: 'file' },
      { key: 'logs', title: '操作日志', path: '/subPackages/admin/pages/logs/operation', icon: 'list' },
      { key: 'access-logs', title: '访问日志', path: '/subPackages/admin/pages/logs/access', icon: 'eye' },
    ],
  },
]

export const STAFF_ROLES = ['admin', 'editor'] as const

export function isStaffRole(role?: string): boolean {
  if (!role) return false
  const r = role.toLowerCase()
  return STAFF_ROLES.includes(r as (typeof STAFF_ROLES)[number]) || r.includes('admin') || r.includes('editor')
}
