/**
 * 로그인 결과 카탈로그
 *
 * SSOT: backend kcg.auth_login_history.login_result
 * 사용처: LoginHistoryView
 */

import type { BadgeIntent } from '@lib/theme/variants';

export type LoginResult = 'SUCCESS' | 'FAILED' | 'LOCKED';

interface LoginResultMeta {
  code: LoginResult;
  i18nKey: string;
  fallback: { ko: string; en: string };
  intent: BadgeIntent;
}

export const LOGIN_RESULTS: Record<LoginResult, LoginResultMeta> = {
  SUCCESS: {
    code: 'SUCCESS',
    i18nKey: 'loginResult.SUCCESS',
    fallback: { ko: '성공', en: 'Success' },
    intent: 'success',
  },
  FAILED: {
    code: 'FAILED',
    i18nKey: 'loginResult.FAILED',
    fallback: { ko: '실패', en: 'Failed' },
    intent: 'high',
  },
  LOCKED: {
    code: 'LOCKED',
    i18nKey: 'loginResult.LOCKED',
    fallback: { ko: '계정 잠금', en: 'Locked' },
    intent: 'critical',
  },
};

export function getLoginResultIntent(s: string): BadgeIntent {
  return LOGIN_RESULTS[s as LoginResult]?.intent ?? 'muted';
}
export function getLoginResultLabel(
  s: string,
  t: (k: string, opts?: { defaultValue?: string }) => string,
  lang: 'ko' | 'en' = 'ko',
): string {
  const meta = LOGIN_RESULTS[s as LoginResult];
  if (!meta) return s;
  return t(meta.i18nKey, { defaultValue: meta.fallback[lang] });
}
