import { useTranslation } from "react-i18next";
import { lazy, Suspense } from "react";
import { Spin } from "antd";
import useSetPageTitle from "../../Hooks/useSetPageTitle";
import { useParams } from "react-router-dom";
import { ParamsEnum } from "../../enums/params";
import { useGetAllUnit } from "../../api/unit";
import { ModalEnum } from "../../enums/Model";
import { useDeleteLesson } from "../../api/lesson";
import { useGetAllGrade } from "../../api/grade";
import { useGetAllCurriculum } from "../../api/curriculum";
import { useGetAllSubject } from "../../api/subject";

const Table = lazy(() => import('./Table'));
const AddModalForm = lazy(() => import('./Model/AddModel'));
const EditModalForm = lazy(() => import('./Model/EditModel'));
const DeleteModelsForm = lazy(() => import('../../Layout/Dashboard/DeleteModels'));

const TableHeader = () => {
  const [t] = useTranslation();
  const deleteMutation = useDeleteLesson();

  const { unit_id,curriculum_id,grade_id ,subject_id} = useParams<ParamsEnum>();
  const { data: unit } = useGetAllUnit({ show: unit_id });


  const { data: Subject } = useGetAllSubject({
    show: subject_id,
  });
  const { data: grade } = useGetAllGrade({
    show: grade_id,
  });
  const { data: Curriculum } = useGetAllCurriculum({
    show: curriculum_id,
  });

  const gradeName = grade?.data?.name ?? "";  
  const SubjectName = Subject?.data?.name ?? "";
  const CurriculumName = Curriculum?.data?.name ?? "";
  const unitName = unit?.data?.name ?? "";


  useSetPageTitle( t(`page_header.grade`)+ "/"+ gradeName +"/"+t(`PageTitle.subject`)+"/"+SubjectName+"/"+t("PageTitle.curriculum")+"/"+CurriculumName+"/"+t("PageTitle.unit")+"/"+unitName+"/"+t("PageTitle.lesson"));



  return (
    <div className="TableWithHeader">
      <Suspense fallback={<Spin />}>
        <header>
          <h6>
            {t("models.lessons")} {SubjectName} {unitName}
          </h6>
        </header>
        <Table />
        <AddModalForm />
      <EditModalForm />
      <DeleteModelsForm
          deleteMutation={deleteMutation}
          ModelEnum={ModalEnum?.LESSON_DELETE}
          />
      </Suspense>
    </div>
  );
};

export default TableHeader;
