export const TX_KEY_MAP: Record<string, string> = {
  MANUAL_DEPOSIT: 'finance.tx.deposit',
  ADMIN_DEPOSIT: 'finance.tx.admin_deposit',
  AGENT_DEPOSIT: 'finance.tx.agent_deposit',
  INITIAL_DEPOSIT: 'finance.tx.admin_deposit',
  MANUAL_WITHDRAW: 'finance.tx.withdraw',
  ADMIN_WITHDRAW: 'finance.tx.admin_withdraw',
  AGENT_WITHDRAW: 'finance.tx.agent_withdraw',
  MANUAL_ADJUST: 'finance.tx.adjust',
  BET_FREEZE: 'finance.tx.bet_freeze',
  BET_DEDUCT: 'finance.tx.bet_deduct',
  BET_SETTLE_WIN: 'finance.tx.bet_win',
  BET_SETTLE_LOSE: 'finance.tx.bet_lose',
  BET_SETTLE_PUSH: 'finance.tx.bet_push',
  BET_WIN: 'finance.tx.bet_win',
  BET_REFUND: 'finance.tx.bet_refund',
  BET_VOID: 'finance.tx.bet_void',
  BET_VOID_REFUND: 'finance.tx.bet_void',
  CASHBACK: 'finance.tx.cashback',
  CASHBACK_DEPOSIT: 'finance.tx.cashback',
  RESETTLE_REVERSE: 'finance.tx.resettle',
  DEPOSIT: 'finance.tx.deposit',
  WITHDRAW: 'finance.tx.withdraw',
  PLAYER_DEPOSIT: 'finance.tx.player_deposit',
};

export function walletTxTypeKey(type: string): string {
  return TX_KEY_MAP[type.toUpperCase()] ?? '';
}

export const DEPOSIT_RECHARGE_TYPES = new Set([
  'MANUAL_DEPOSIT',
  'ADMIN_DEPOSIT',
  'AGENT_DEPOSIT',
  'INITIAL_DEPOSIT',
  'DEPOSIT',
  'PLAYER_DEPOSIT',
]);

export const DEPOSIT_METHOD_KEY_MAP: Record<string, string> = {
  MANUAL_ADMIN: 'finance.deposit_method.manual_admin',
  MANUAL_AGENT: 'finance.deposit_method.manual_agent',
  MANUAL: 'finance.deposit_method.manual',
};

export function walletDepositMethodLabel(
  row: {
    transactionType: string;
    depositMethodKey?: string | null;
    depositMethodName?: string | null;
  },
  t: (key: string) => string,
): string {
  if (!DEPOSIT_RECHARGE_TYPES.has(row.transactionType.toUpperCase())) return '—';
  if (row.depositMethodName?.trim()) return row.depositMethodName.trim();
  if (row.depositMethodKey) {
    const key = DEPOSIT_METHOD_KEY_MAP[row.depositMethodKey];
    return key ? t(key) : row.depositMethodKey;
  }
  const type = row.transactionType.toUpperCase();
  if (type === 'ADMIN_DEPOSIT') return t('finance.tx.admin_deposit');
  if (type === 'AGENT_DEPOSIT') return t('finance.tx.agent_deposit');
  if (type === 'INITIAL_DEPOSIT') return t('finance.tx.admin_deposit');
  if (type === 'PLAYER_DEPOSIT') return t('finance.tx.player_deposit');
  return '—';
}
