import type { FinanceApi } from '#/api/core/finance';

export const STATUS_CONFIG: Record<
  FinanceApi.TransactionStatus,
  { label: string; color: string; description: string; order: number }
> = {
  draft: {
    label: '草稿',
    color: 'default',
    description: '尚未提交或待完善的报销信息',
    order: 0,
  },
  pending: {
    label: '待审批',
    color: 'processing',
    description: '等待审批人审核的报销申请',
    order: 1,
  },
  approved: {
    label: '已通过',
    color: 'success',
    description: '审批通过，待支付或报销完成',
    order: 2,
  },
  rejected: {
    label: '已驳回',
    color: 'error',
    description: '审批被驳回，需要发起人处理',
    order: 3,
  },
  paid: {
    label: '已报销',
    color: 'purple',
    description: '已完成报销或费用报销入账',
    order: 4,
  },
};

export const STATUS_OPTIONS = Object.entries(STATUS_CONFIG)
  .sort((a, b) => a[1].order - b[1].order)
  .map(([value, config]) => ({
    label: `${config.label}`,
    value: value as FinanceApi.TransactionStatus,
  }));

export function formatStatus(status: FinanceApi.TransactionStatus) {
  return STATUS_CONFIG[status] ?? STATUS_CONFIG.pending;
}
