export type DetailPaymentStatus = '未收款' | '部分收款' | '已结清';

export const DETAIL_PAYMENT_STATUS_OPTIONS: DetailPaymentStatus[] = [
  '未收款',
  '部分收款',
  '已结清',
];

const STATUS_SORT_ORDER: Record<DetailPaymentStatus, number> = {
  未收款: 0,
  部分收款: 1,
  已结清: 2,
};

export const DETAIL_PAYMENT_STATUS_CLASS: Record<DetailPaymentStatus, string> = {
  未收款: 'ldb-status--unpaid',
  部分收款: 'ldb-status--partial',
  已结清: 'ldb-status--paid',
};

/** 根据实收金额与应收合计计算收款状态 */
export function resolveDetailPaymentStatus(
  receivableTotal: number,
  receivedAmount: number | null | undefined,
): DetailPaymentStatus {
  const received = receivedAmount ?? 0;
  if (received <= 0) return '未收款';
  if (received >= receivableTotal) return '已结清';
  return '部分收款';
}

export function paymentStatusSortValue(
  receivableTotal: number,
  receivedAmount: number | null | undefined,
): number {
  return STATUS_SORT_ORDER[resolveDetailPaymentStatus(receivableTotal, receivedAmount)];
}
