/**
 * 业务对象状态颜色（ElTag type）集中配置
 *
 * 各业务域的 statusCode → ElTag type 在此统一维护，避免散落在各业务模块。
 * 未来若后端状态字典返回颜色字段，可在调用方优先取后端值，缺失时回退此映射。
 */

export type StatusTagType = 'primary' | 'success' | 'warning' | 'info' | 'danger';

export type StatusDomain =
  | 'projectExecution'
  | 'projectTask'
  | 'executionAssignee'
  | 'taskAssigneeMember'
  | 'project'
  | 'product'
  | 'productRequirement'
  | 'projectRequirement'
  | 'workOrder'
  | 'workReport'
  | 'performanceSheet'
  | 'personalItem'
  | 'overtimeApplication'
  | 'feedback';

const statusTagTypeRegistry: Record<StatusDomain, Record<string, StatusTagType>> = {
  // 项目-执行
  projectExecution: {
    pending: 'info',
    active: 'primary',
    paused: 'warning',
    completed: 'success',
    cancelled: 'danger'
  },
  // 项目-任务
  projectTask: {
    pending: 'info',
    active: 'primary',
    paused: 'warning',
    completed: 'success',
    cancelled: 'danger'
  },
  // 执行协办人变更事件
  executionAssignee: {
    join: 'success',
    inactive: 'danger',
    owner_transfer_in: 'warning',
    owner_transfer_out: 'warning'
  },
  // 任务协办人变更事件
  taskAssigneeMember: {
    join: 'success',
    inactive: 'danger'
  },
  // 项目（待补全）
  project: {},
  // 产品（待补全）
  product: {},
  // 产品需求
  productRequirement: {
    pending_claim: 'info',
    pending_review: 'info',
    pending_dispatch: 'primary',
    reviewed: 'success',
    review_rejected: 'danger',
    implementing: 'primary',
    accepted: 'success',
    closed: 'danger',
    rejected: 'danger',
    cancelled: 'danger'
  },
  // 项目需求
  projectRequirement: {
    pending_claim: 'info',
    pending_review: 'info',
    reviewed: 'success',
    review_rejected: 'danger',
    implementing: 'primary',
    accepted: 'success',
    closed: 'danger',
    rejected: 'danger',
    cancelled: 'danger'
  },
  // 工单（待补全）
  workOrder: {},
  // 工作报告
  workReport: {
    draft: 'info',
    pending_approval: 'warning',
    approved: 'success',
    rejected: 'danger'
  },
  // 绩效表
  performanceSheet: {
    draft: 'info',
    sent: 'warning',
    confirmed: 'success',
    rejected: 'danger'
  },
  // 个人事项
  personalItem: {
    pending: 'info',
    active: 'primary',
    completed: 'success',
    cancelled: 'danger'
  },
  // 业务学习
  overtimeApplication: {
    pending: 'warning',
    approved: 'success',
    rejected: 'danger'
  },
  // 意见反馈
  feedback: {
    '1': 'warning', // 待处理
    '2': 'primary', // 处理中
    '3': 'success', // 已处理
    '4': 'info' // 已忽略
  }
};

export function getStatusTagType(domain: StatusDomain, statusCode: string | null | undefined): StatusTagType {
  if (!statusCode) {
    return 'info';
  }

  return statusTagTypeRegistry[domain]?.[statusCode] || 'info';
}

export function getPersonalItemStatusTagType(statusCode: string | null | undefined) {
  return getStatusTagType('personalItem', statusCode);
}

export function getFeedbackStatusTagType(statusCode: string | number | null | undefined) {
  return getStatusTagType(
    'feedback',
    statusCode === null || statusCode === undefined ? statusCode : String(statusCode)
  );
}
