import { useTranslation } from "react-i18next";
import { lazy, Suspense } from "react";
import { Spin } from "antd";
import { useParams } from "react-router-dom";
import { ParamsEnum } from "../../enums/params";
import { useGetAllUnit } from "../../api/unit";
import useSetPageTitle from "../../Hooks/useSetPageTitle";
import { useGetAllLesson } from "../../api/lesson";
import { useDeleteQuestion } from "../../api/Question";
import DeleteModels from "../../Layout/Dashboard/DeleteModels";
import { ModalEnum } from "../../enums/Model";
const Table = lazy(() => import("./Table"));

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

  const deleteMutation = useDeleteQuestion();

  const {  unit_id,lesson_id } = useParams<ParamsEnum>();
  const { data: unit } = useGetAllUnit({ show: unit_id });
  const { data: lesson } = useGetAllLesson({ show: lesson_id });
  const unitName = unit?.data?.name ?? "";
  const SubjectName = unit?.data?.subject?.name ?? "";
  const lessonName = lesson?.data?.name ?? "";

  useSetPageTitle(
    t(`page_header.subject`) +
      "/" +
      `${SubjectName}` +
      "/" +
      t(`PageTitle.unit`) +
      "/" +
      `${unitName}` +
      "/" +
      t(`PageTitle.lesson`) +
      "/" +
      `${lessonName}` +
      "/" +
      t(`PageTitle.questions`),
  );

  return (
    <div className="TableWithHeader">
      <Suspense fallback={<Spin />}>
        <header>
          <h6>
            {t("models.Question")} {SubjectName} {unitName} {lessonName}
          </h6>
        </header>
        <Table />
      </Suspense>
      <DeleteModels
          deleteMutation={deleteMutation}
          ModelEnum={ModalEnum?.QUESTION_DELETE}
          />
    </div>
  );
};

export default TableHeader;
