import type { AssignmentType } from "@/types";
import { useTranslation } from "i18next-vue";

export function assertUnreachable(msg: string): never {
  throw new Error("Didn't expect to get here, " + msg);
}

export function stringifyParse(obj: any): any {
  return JSON.parse(JSON.stringify(obj));
}

function createCourseUrl(courseSlug: string | undefined, specificSub: string): string {
  if (!courseSlug) {
    return "/";
  }

  if (["learn", "media", "competence", "cockpit", "mentor"].includes(specificSub)) {
    return `/course/${courseSlug}/${specificSub}`;
  }
  return `/course/${courseSlug}`;
}

export function getCompetenceNaviUrl(courseSlug: string | undefined): string {
  return createCourseUrl(courseSlug, "competence");
}

export function getMediaCenterUrl(courseSlug: string | undefined): string {
  return createCourseUrl(courseSlug, "media");
}

export function getLearningPathUrl(courseSlug: string | undefined): string {
  return createCourseUrl(courseSlug, "learn");
}

export function getCockpitUrl(courseSlug: string | undefined): string {
  return createCourseUrl(courseSlug, "cockpit");
}

export function getLearningMentorManagementUrl(courseSlug: string | undefined): string {
  return createCourseUrl(courseSlug, "mentor");
}

export function getAssignmentTypeTitle(assignmentType: AssignmentType): string {
  const { t } = useTranslation();

  switch (assignmentType) {
    case "CASEWORK":
      return t("learningContentTypes.casework");
    case "PRAXIS_ASSIGNMENT":
      return t("learningContentTypes.praxisAssignment");
    case "PREP_ASSIGNMENT":
      return t("learningContentTypes.prepAssignment");
    case "REFLECTION":
      return t("learningContentTypes.reflection");
    case "CONDITION_ACCEPTANCE":
      return t("learningContentTypes.task");
    case "EDONIQ_TEST":
      return t("learningContentTypes.edoniqTest");
    default:
      return "unknown";
  }
}

export function getAssignmentTypeIcon(assignmentType: AssignmentType): string {
  switch (assignmentType) {
    case "REFLECTION":
      return "it-icon-lc-reflection";
    default:
      return "it-icon-lc-assignment";
  }
}
