import type { TFunction } from "i18next";

export function settlementBillStatusLabel(
  status: string,
  t: TFunction<"settlementCenter">,
): string {
  const key = `billStatus.${status}` as const;
  return t(key, { defaultValue: status });
}

export function settlementBillTypeLabel(
  billType: string,
  t: TFunction<["settlementCenter", "agents"]>,
): string {
  if (billType === "player") {
    return t("agents:settlementBills.typePlayer", { defaultValue: "玩家账单" });
  }
  if (billType === "agent") {
    return t("agents:settlementBills.typeAgent", { defaultValue: "代理层级账单" });
  }
  if (billType === "adjustment") {
    return t("settlementCenter:billType.adjustment", { defaultValue: "补差单" });
  }
  if (billType === "reversal") {
    return t("settlementCenter:billType.reversal", { defaultValue: "冲正单" });
  }
  if (billType === "bad_debt") {
    return t("settlementCenter:billType.badDebt", { defaultValue: "坏账核销" });
  }

  return billType;
}

export function settlementPeriodStatusLabel(
  status: string,
  t: TFunction<"settlementCenter">,
): string {
  if (status === "open") {
    return t("filters.statusOpen", { defaultValue: "进行中" });
  }
  if (status === "closed") {
    return t("filters.statusClosed", { defaultValue: "已关账" });
  }
  if (status === "completed") {
    return t("filters.statusCompleted", { defaultValue: "已结清" });
  }

  return status;
}

export function creditLedgerReasonLabel(
  reason: string,
  t: TFunction<"settlementCenter">,
): string {
  if (reason === "bet") {
    return t("creditLedger.reason.bet", { defaultValue: "下注冻结" });
  }
  if (reason === "game_settlement") {
    return t("creditLedger.reason.game_settlement", { defaultValue: "开奖结算" });
  }
  if (reason === "bill_settlement") {
    return t("creditLedger.reason.bill_settlement", { defaultValue: "账期收付" });
  }
  if (reason === "game_settlement_reversal") {
    return t("creditLedger.reason.game_settlement_reversal", { defaultValue: "开奖冲正" });
  }
  if (reason === "bet_hold") {
    return t("creditLedger.reason.bet_hold", { defaultValue: "下注冻结" });
  }
  if (reason === "bet_hold_release") {
    return t("creditLedger.reason.bet_hold_release", { defaultValue: "占用释放" });
  }
  if (reason === "game_settlement_win") {
    return t("creditLedger.reason.game_settlement_win", { defaultValue: "开奖结算入账" });
  }
  if (reason === "game_settlement_loss") {
    return t("creditLedger.reason.game_settlement_loss", { defaultValue: "开奖结算扣款" });
  }
  if (reason === "settlement_confirm") {
    return t("creditLedger.reason.settlement_confirm", { defaultValue: "账期结算确认" });
  }
  if (reason === "settlement_payout") {
    return t("creditLedger.reason.settlement_payout", { defaultValue: "结算收付入账" });
  }

  const key = `creditLedger.reason.${reason}` as const;
  return t(key, { defaultValue: reason });
}

export function settlementAdjustmentTypeLabel(
  type: string,
  t: TFunction<"settlementCenter">,
): string {
  if (type === "bad_debt") {
    return t("adjustmentType.bad_debt", { defaultValue: "坏账核销" });
  }

  const key = `adjustmentType.${type}` as const;
  return t(key, { defaultValue: type });
}

export function settlementPaymentStatusLabel(
  status: string,
  t: TFunction<"settlementCenter">,
): string {
  const key = `paymentStatus.${status}` as const;
  return t(key, { defaultValue: status });
}
