import {
  getTrainingCategoryLabel,
  thaiTrainingCategoryLabels
} from '@/constants/thai-labels';

export const onlineLessonCategoryValues = ['K', 'S', 'A'] as const;

export type OnlineLessonCategory = (typeof onlineLessonCategoryValues)[number];

export const onlineLessonCategoryOptions = onlineLessonCategoryValues.map((value) => ({
  value,
  label: `${value} - ${thaiTrainingCategoryLabels[value]}`
}));

export function isOnlineLessonCategory(value: string | null | undefined): value is OnlineLessonCategory {
  return onlineLessonCategoryValues.includes(value as OnlineLessonCategory);
}

export function normalizeOnlineLessonCategory(
  value: string | null | undefined
): OnlineLessonCategory | null {
  const normalized = value?.trim().toUpperCase();

  if (!normalized) {
    return null;
  }

  if (normalized === 'K' || normalized.startsWith('KNOWLEDGE')) {
    return 'K';
  }

  if (normalized === 'S' || normalized.startsWith('SKILL')) {
    return 'S';
  }

  if (normalized === 'A' || normalized.startsWith('ATTITUDE')) {
    return 'A';
  }

  return null;
}

export function getOnlineLessonCategoryLabel(value: string | null | undefined) {
  const normalized = normalizeOnlineLessonCategory(value);
  return normalized ? `${normalized} - ${getTrainingCategoryLabel(normalized)}` : '-';
}
