/**
 * 군사 훈련구역 타입 카탈로그
 *
 * 사용처: MapControl 훈련구역 마커/배지
 */

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

export type TrainingZoneType = 'NAVY' | 'AIRFORCE' | 'ARMY' | 'ADD' | 'KCG';

interface TrainingZoneTypeMeta {
  code: TrainingZoneType;
  i18nKey: string;
  fallback: { ko: string; en: string };
  intent: BadgeIntent;
  hex: string;
}

export const TRAINING_ZONE_TYPES: Record<TrainingZoneType, TrainingZoneTypeMeta> = {
  NAVY: {
    code: 'NAVY',
    i18nKey: 'trainingZone.NAVY',
    fallback: { ko: '해군 훈련 구역', en: 'Navy Training Zone' },
    intent: 'warning',
    hex: '#eab308',
  },
  AIRFORCE: {
    code: 'AIRFORCE',
    i18nKey: 'trainingZone.AIRFORCE',
    fallback: { ko: '공군 훈련 구역', en: 'Airforce Training Zone' },
    intent: 'critical',
    hex: '#ec4899',
  },
  ARMY: {
    code: 'ARMY',
    i18nKey: 'trainingZone.ARMY',
    fallback: { ko: '육군 훈련 구역', en: 'Army Training Zone' },
    intent: 'success',
    hex: '#22c55e',
  },
  ADD: {
    code: 'ADD',
    i18nKey: 'trainingZone.ADD',
    fallback: { ko: '국방과학연구소', en: 'ADD' },
    intent: 'info',
    hex: '#3b82f6',
  },
  KCG: {
    code: 'KCG',
    i18nKey: 'trainingZone.KCG',
    fallback: { ko: '해양경찰청', en: 'KCG' },
    intent: 'purple',
    hex: '#a855f7',
  },
};

const LEGACY_KO: Record<string, TrainingZoneType> = {
  '해군': 'NAVY',
  '공군': 'AIRFORCE',
  '육군': 'ARMY',
  '국과연': 'ADD',
  '해경': 'KCG',
};

export function getTrainingZoneMeta(t: string): TrainingZoneTypeMeta | undefined {
  if (TRAINING_ZONE_TYPES[t as TrainingZoneType]) return TRAINING_ZONE_TYPES[t as TrainingZoneType];
  const code = LEGACY_KO[t];
  return code ? TRAINING_ZONE_TYPES[code] : undefined;
}

export function getTrainingZoneIntent(t: string): BadgeIntent {
  return getTrainingZoneMeta(t)?.intent ?? 'muted';
}
export function getTrainingZoneHex(t: string): string {
  return getTrainingZoneMeta(t)?.hex ?? '#6b7280';
}
export function getTrainingZoneLabel(
  type: string,
  t: (k: string, opts?: { defaultValue?: string }) => string,
  lang: 'ko' | 'en' = 'ko',
): string {
  const meta = getTrainingZoneMeta(type);
  if (!meta) return type;
  return t(meta.i18nKey, { defaultValue: meta.fallback[lang] });
}
