export const quickPromptItems = [
  '如何申请差旅费用？',
  '报销标准是多少？',
  '预算有哪些科目余额？',
  '发票丢失了如何处理？'
]

export const assistantCapabilities = [
  {
    key: 'expense-application',
    title: '费用申请',
    primary: '智能识别规划',
    secondary: '快速创建申请',
    icon: 'mdi mdi-file-document-plus-outline',
    tone: 'green',
    prompt: '帮我新建一笔费用申请，并检查需要补充哪些信息。'
  },
  {
    key: 'quick-reimbursement',
    title: '快速报销',
    primary: '智能报销流程',
    secondary: '财务流程简化',
    icon: 'mdi mdi-wallet-outline',
    tone: 'blue',
    prompt: '帮我整理票据并生成一笔可提交的报销单。'
  },
  {
    key: 'budget-planning',
    title: '预算编制',
    primary: '预算查询分析',
    secondary: '超标预警提醒',
    icon: 'mdi mdi-chart-pie',
    tone: 'emerald',
    prompt: '帮我查询本月预算使用情况，并提醒可能超标的费用。'
  },
  {
    key: 'quick-approval',
    title: '快速审批',
    primary: '审批凭证说明',
    secondary: '进度实时查询',
    icon: 'mdi mdi-clipboard-check-outline',
    tone: 'violet',
    prompt: '帮我查询报销审批进度，并说明当前卡在哪个节点。'
  },
  {
    key: 'finance-analysis',
    title: '财务分析',
    primary: '费用结构洞察',
    secondary: '趋势对比分析',
    icon: 'mdi mdi-chart-line',
    tone: 'cyan',
    prompt: '帮我分析近期费用结构与支出趋势，并给出优化建议。'
  },
  {
    key: 'company-policy',
    title: '公司制度',
    primary: '制度检索解读',
    secondary: '政策实时更新',
    icon: 'mdi mdi-book-open-page-variant-outline',
    tone: 'amber',
    prompt: '帮我解释最新报销制度，并列出需要注意的条款。'
  }
]

const FINANCIAL_CAPABILITY_KEYS = new Set(['budget-planning', 'finance-analysis'])
const FINANCIAL_CAPABILITY_ROLE_CODES = new Set(['budget_monitor', 'executive', 'admin'])
const FINANCIAL_CAPABILITY_ROLE_LABELS = new Set(['预算监控员', '高级财务人员', '管理员'])

function normalizeRoleCodes(user = {}) {
  const rawCodes = Array.isArray(user.roleCodes)
    ? user.roleCodes
    : Array.isArray(user.role_codes)
      ? user.role_codes
      : []
  return rawCodes.map((code) => String(code || '').trim().toLowerCase()).filter(Boolean)
}

export function canViewFinancialWorkbenchCapabilities(user = {}) {
  const roleLabel = String(user.role || '').trim()
  return Boolean(user.isAdmin)
    || FINANCIAL_CAPABILITY_ROLE_LABELS.has(roleLabel)
    || normalizeRoleCodes(user).some((code) => FINANCIAL_CAPABILITY_ROLE_CODES.has(code))
}

export function filterAssistantCapabilitiesForUser(user = {}) {
  const canViewFinancial = canViewFinancialWorkbenchCapabilities(user)
  return assistantCapabilities.filter((item) => canViewFinancial || !FINANCIAL_CAPABILITY_KEYS.has(item.key))
}

export function resolveWorkbenchCapabilityGridClass(user = {}) {
  return canViewFinancialWorkbenchCapabilities(user) ? 'capability-grid--privileged' : 'capability-grid--standard'
}

export const todoItems = [
  {
    title: '待补材料',
    description: '差旅报销-北京市市场调研差旅费',
    status: '待补材料',
    statusTone: 'warning',
    due: '今天 18:00 截止',
    iconKey: 'receipts',
    color: 'var(--warning)',
    accent: 'var(--warning-soft)'
  },
  {
    title: '待提交申请',
    description: '费用申请-5月市场活动费用申请',
    status: '待提交',
    statusTone: 'success',
    due: '明天 10:00 截止',
    iconKey: 'travelDraft',
    color: 'var(--theme-primary)',
    accent: 'var(--theme-primary-soft)'
  },
  {
    title: '退回修改',
    description: '办公用品采购报销单',
    status: '退回修改',
    statusTone: 'danger',
    due: '2026-05-03',
    iconKey: 'procurement',
    color: 'var(--danger)',
    accent: 'var(--danger-soft)'
  },
  {
    title: '待确认票据',
    description: '招待费报销单',
    status: '待确认',
    statusTone: 'info',
    due: '2026-05-04',
    iconKey: 'hospitality',
    color: 'var(--chart-blue)',
    accent: 'color-mix(in srgb, var(--chart-blue) 10%, #ffffff)'
  },
  {
    title: '待审批',
    description: '培训费报销单',
    status: '待审批',
    statusTone: 'orange',
    due: '2026-05-05',
    iconKey: 'transport',
    color: 'var(--chart-amber)',
    accent: 'color-mix(in srgb, var(--chart-amber) 12%, #ffffff)'
  }
]

export const progressSteps = ['草稿中', '审批中', '待付款', '已完成']

export const progressItems = [
  {
    id: 'BX-202605-0031',
    title: '北京市市场调研差旅费',
    amount: '¥3,280.00',
    status: '审批中',
    statusTone: 'success',
    activeStep: 1
  },
  {
    id: 'BX-202605-0028',
    title: '5月市场活动费用申请',
    amount: '¥8,750.00',
    status: '审批中',
    statusTone: 'success',
    activeStep: 1
  },
  {
    id: 'BX-202605-0022',
    title: '办公用品采购报销单',
    amount: '¥1,126.00',
    status: '待付款',
    statusTone: 'warning',
    activeStep: 2
  },
  {
    id: 'BX-202604-0049',
    title: '上海出差差旅费',
    amount: '¥2,458.00',
    status: '已完成',
    statusTone: 'muted',
    activeStep: 3
  },
  {
    id: 'BX-202604-0033',
    title: '客户招待费',
    amount: '¥945.00',
    status: '已完成',
    statusTone: 'muted',
    activeStep: 3
  }
]

export function buildExpenseStatItems(summary = {}) {
  return [
    {
      key: 'monthly-count',
      label: '本月报销笔数',
      value: summary.monthlyCount ?? 0,
      unit: '笔',
      tone: 'primary',
      icon: 'mdi mdi-text-box-check-outline'
    },
    {
      key: 'monthly-amount',
      label: '本月报销金额',
      value: summary.monthlyAmountLabel || '¥0',
      unit: '',
      tone: 'amount',
      icon: 'mdi mdi-cash-multiple'
    },
    {
      key: 'total-count',
      label: '累计报销笔数',
      value: summary.totalCount ?? 0,
      unit: '笔',
      tone: 'muted',
      icon: 'mdi mdi-clipboard-text-outline'
    },
    {
      key: 'total-amount',
      label: '累计报销金额',
      value: summary.totalAmountLabel || '¥0',
      unit: '',
      tone: 'amount',
      icon: 'mdi mdi-bank-outline'
    },
    {
      key: 'in-review',
      label: '审批中单据',
      value: summary.inReviewCount ?? 0,
      unit: '笔',
      tone: 'warning',
      icon: 'mdi mdi-timer-sand'
    },
    {
      key: 'pending-payment',
      label: '待付款单据',
      value: summary.pendingPaymentCount ?? 0,
      unit: '笔',
      tone: 'info',
      icon: 'mdi mdi-credit-card-outline'
    }
  ]
}

/** 用户画像历史示例数据：首页已切换为后端真实画像，仅保留给旧演示入口兜底。 */
export const usageProfileMetrics = [
  {
    key: 'stay-duration',
    label: '系统停留时长',
    value: '128.5',
    unit: '小时',
    hint: '近 30 天累计',
    icon: 'mdi mdi-clock-outline',
    tone: 'primary'
  },
  {
    key: 'ai-usage',
    label: 'AI 使用次数',
    value: '86',
    unit: '次',
    hint: '含报销助手与制度问答',
    icon: 'mdi mdi-robot-outline',
    tone: 'violet'
  },
  {
    key: 'token-usage',
    label: 'Token 消耗',
    value: '1.42',
    unit: '万',
    hint: '本月模型调用累计',
    icon: 'mdi mdi-lightning-bolt-outline',
    tone: 'amber'
  },
  {
    key: 'audit-duration',
    label: '平均审核时长',
    value: '18.6',
    unit: '小时',
    hint: '本月已办结单据',
    icon: 'mdi mdi-timer-sand',
    tone: 'success'
  },
  {
    key: 'submit-efficiency',
    label: '平均提单耗时',
    value: '12',
    unit: '分钟',
    hint: '从打开助手到提交',
    icon: 'mdi mdi-speedometer',
    tone: 'cyan'
  },
  {
    key: 'auto-pass-rate',
    label: '智能预审通过率',
    value: '92',
    unit: '%',
    hint: 'AI 预审后无需补材',
    icon: 'mdi mdi-shield-check-outline',
    tone: 'emerald'
  }
]

export const expenseProfileTags = [
  {
    code: 'ai-heavy-user',
    label: 'AI 重度用户',
    displayLabel: 'AI 协作活跃',
    tone: 'behavior',
    score: 86,
    reason: '近 30 天 AI 使用 86 次，覆盖报销助手、制度问答和票据整理。'
  },
  {
    code: 'fast-submitter',
    label: '极速提单人',
    displayLabel: '提单效率高',
    tone: 'positive',
    score: 82,
    reason: '平均提单耗时 12 分钟，明显低于常规人工录入节奏。'
  },
  {
    code: 'clean-precheck',
    label: '预审稳定',
    displayLabel: '预审通过稳定',
    tone: 'positive',
    score: 92,
    reason: '智能预审通过率 92%，近期补材压力较低。'
  },
  {
    code: 'review-wait',
    label: '审核等待偏长',
    displayLabel: '审核响应需关注',
    tone: 'risk',
    score: 64,
    reason: '平均审核时长 18.6 小时，仍有压缩空间。'
  },
  {
    code: 'active-operator',
    label: '高频操作人',
    displayLabel: '操作频率高',
    tone: 'behavior',
    score: 78,
    reason: '近 30 天在申请、查询、补材、AI 问答之间切换频繁。'
  }
]

export const expenseProfileRadarDimensions = [
  { code: 'ai_collaboration', label: 'AI 协作', score: 86 },
  { code: 'submit_efficiency', label: '提单效率', score: 82 },
  { code: 'precheck_quality', label: '预审质量', score: 92 },
  { code: 'review_response', label: '审核响应', score: 64 },
  { code: 'material_completeness', label: '材料完整', score: 76 },
  { code: 'expense_rhythm', label: '费用节奏', score: 68 }
]

export const expenseProfileOperations = [
  {
    id: 'OP-0528-01',
    time: '今天 09:42',
    action: '上传票据并触发智能识别',
    target: '北京市市场调研差旅费',
    channel: '报销助手',
    status: '识别完成',
    tone: 'success'
  },
  {
    id: 'OP-0528-02',
    time: '今天 09:51',
    action: '发起 AI 预审',
    target: 'BX-202605-0031',
    channel: '智能预审',
    status: '通过',
    tone: 'success'
  },
  {
    id: 'OP-0527-03',
    time: '昨天 17:18',
    action: '查询审批进度',
    target: '5月市场活动费用申请',
    channel: '个人工作台',
    status: '审批中',
    tone: 'warning'
  },
  {
    id: 'OP-0527-04',
    time: '昨天 14:06',
    action: '补充业务事由',
    target: '办公用品采购报销单',
    channel: '单据详情',
    status: '已保存',
    tone: 'info'
  },
  {
    id: 'OP-0526-05',
    time: '05-26 11:33',
    action: '制度问答检索',
    target: '差旅住宿标准',
    channel: '制度问答',
    status: '已回复',
    tone: 'muted'
  }
]
