import { FAVORITE_LINK } from '../../constants';

export function getLessonVocabularyLink(i_active_lesson_idx: string, i_cat_idx: string, i_word_idx: string): string {
  let s_active_lesson_idx = parseInt(i_active_lesson_idx);
  let s_cat_idx = parseInt(i_cat_idx);
  let s_word_idx = parseInt(i_word_idx);
  return `/lesson_word_page/v/${s_active_lesson_idx}/${s_cat_idx}/${s_word_idx}`;
}

export function getFavLessonVocabularyLink(i_active_lesson_idx: string, i_cat_idx: string, i_word_idx: string): string {
  let s_active_lesson_idx = parseInt(i_active_lesson_idx);
  let s_cat_idx = parseInt(i_cat_idx);
  let s_word_idx = parseInt(i_word_idx);
  return `/fav/v/${s_active_lesson_idx}/${s_cat_idx}/${s_word_idx}`;
}

export function parseLessonVocabularyLink(s: string):
  | {
      active_lesson_idx: number;
      cat_idx: number;
      word_idx: number;
    }
  | undefined {
  const reg = /^\/lesson_word_page\/v\/(\d+)\/(\d+)\/(\d+)$/;
  const match = s.match(reg);
  if (match) {
    return {
      active_lesson_idx: parseInt(match[1]),
      cat_idx: parseInt(match[2]),
      word_idx: parseInt(match[3])
    };
  }
  return undefined;
}
