import { useTranslation } from "react-i18next";
import { lazy, Suspense } from "react";
import { Spin } from "antd";
import DeleteModel from "./Model/Delete";
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";
const Table = lazy(() => import("./Table"));

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

  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(`page_title.unit`) +
      "/" +
      `${unitName}` +
      "/" +
      t(`page_title.lesson`) +
      "/" +
      `${lessonName}` +
      "/" +
      t(`page_title.questions`),
  );

  return (
    <div className="TableWithHeader">
      <Suspense fallback={<Spin />}>
        <header>
          <h6>
            {t("models.Question")} {SubjectName} {unitName} {lessonName}
          </h6>
        </header>
        <Table />
      </Suspense>
      <DeleteModel />
    </div>
  );
};

export default TableHeader;
