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";

const Table = lazy(() => import("./Table"));
const AddModalForm = lazy(() => import("./Model/AddModel"));
const EditModalForm = lazy(() => import("./Model/EditModel"));
const DeleteModels = lazy(() => import("./Model/Delete"));

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

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

  console.log(unit?.data);

  useSetPageTitle(
    t(`page_header.subject`) +
      "/" +
      `${SubjectName}` +
      "/" +
      t(`page_title.unit`) +
      "/" +
      `${unitName}`,
  );

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

export default TableHeader;
