/**
 * 선박 분석/감시 상태 카탈로그
 *
 * 사용처: ChinaFishing StatusRing, DarkVesselDetection 상태
 */

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

export type VesselSurveillanceStatus = 'TRACKING' | 'WATCHING' | 'CHECKING' | 'NORMAL';

export const VESSEL_SURVEILLANCE_STATUSES: Record<VesselSurveillanceStatus, { i18nKey: string; fallback: { ko: string; en: string }; intent: BadgeIntent }> = {
  TRACKING: {
    i18nKey: 'vesselSurveillance.TRACKING',
    fallback: { ko: '추적중', en: 'Tracking' },
    intent: 'critical',
  },
  WATCHING: {
    i18nKey: 'vesselSurveillance.WATCHING',
    fallback: { ko: '감시중', en: 'Watching' },
    intent: 'warning',
  },
  CHECKING: {
    i18nKey: 'vesselSurveillance.CHECKING',
    fallback: { ko: '확인중', en: 'Checking' },
    intent: 'info',
  },
  NORMAL: {
    i18nKey: 'vesselSurveillance.NORMAL',
    fallback: { ko: '정상', en: 'Normal' },
    intent: 'success',
  },
};

const LEGACY_KO: Record<string, VesselSurveillanceStatus> = {
  '추적중': 'TRACKING',
  '추적 중': 'TRACKING',
  '감시중': 'WATCHING',
  '감시 중': 'WATCHING',
  '확인중': 'CHECKING',
  '확인 중': 'CHECKING',
  '정상': 'NORMAL',
};

export function getVesselSurveillanceIntent(s: string): BadgeIntent {
  if (VESSEL_SURVEILLANCE_STATUSES[s as VesselSurveillanceStatus]) {
    return VESSEL_SURVEILLANCE_STATUSES[s as VesselSurveillanceStatus].intent;
  }
  const code = LEGACY_KO[s];
  return code ? VESSEL_SURVEILLANCE_STATUSES[code].intent : 'muted';
}
export function getVesselSurveillanceLabel(
  s: string,
  t: (k: string, opts?: { defaultValue?: string }) => string,
  lang: 'ko' | 'en' = 'ko',
): string {
  let meta = VESSEL_SURVEILLANCE_STATUSES[s as VesselSurveillanceStatus];
  if (!meta) {
    const code = LEGACY_KO[s];
    if (code) meta = VESSEL_SURVEILLANCE_STATUSES[code];
  }
  if (!meta) return s;
  return t(meta.i18nKey, { defaultValue: meta.fallback[lang] });
}

// ─── ChinaFishing StatusRing 용 (한글 라벨 매핑) ──────────────
export type VesselRiskRing = 'SAFE' | 'SUSPECT' | 'WARNING';

export const VESSEL_RISK_RINGS: Record<VesselRiskRing, { i18nKey: string; fallback: { ko: string; en: string }; intent: BadgeIntent; hex: string }> = {
  SAFE: { i18nKey: 'vesselRing.SAFE', fallback: { ko: '양호', en: 'Safe' }, intent: 'success', hex: '#10b981' },
  SUSPECT: { i18nKey: 'vesselRing.SUSPECT', fallback: { ko: '의심', en: 'Suspect' }, intent: 'high', hex: '#f97316' },
  WARNING: { i18nKey: 'vesselRing.WARNING', fallback: { ko: '경고', en: 'Warning' }, intent: 'critical', hex: '#ef4444' },
};

const RING_LEGACY_KO: Record<string, VesselRiskRing> = {
  '양호': 'SAFE',
  '의심': 'SUSPECT',
  '경고': 'WARNING',
};

export function getVesselRingMeta(s: string) {
  if (VESSEL_RISK_RINGS[s as VesselRiskRing]) return VESSEL_RISK_RINGS[s as VesselRiskRing];
  const code = RING_LEGACY_KO[s];
  return code ? VESSEL_RISK_RINGS[code] : VESSEL_RISK_RINGS.SAFE;
}
