import { FaPlus } from "react-icons/fa";

import useModalHandler from "../../utils/useModalHandler";
import { ModalEnum } from "../../enums/Model";

// import useSetPageTitle from "../../Hooks/useSetPageTitle";
import { useTranslation } from "react-i18next";
import { lazy, Suspense } from "react";
import { Spin } from "antd";
import { canAddTags } from "../../utils/hasAbilityFn";
import useSetPageTitle from "../../Hooks/useSetPageTitle";
const Table = lazy(() => import("./Table"));
const AddModalForm = lazy(() => import("./Model/AddModel"));
const EditModalForm = lazy(() => import("./Model/EditModel"));
const DeleteModalForm = lazy(() => import("./Model/Delete"));
const SearchField = lazy(
  () => import("../../Components/DataTable/SearchField"),
);

const TableHeader = () => {
  const { handel_open_model } = useModalHandler();
  const [t] = useTranslation();
  useSetPageTitle(t(`page_header.tags`));

  return (
    <div className="TableWithHeader">
      <Suspense fallback={<Spin />}>
        <header className="d-flex justify-content-between">
          <SearchField
            searchBy="name"
            placeholder={t("practical.search_here")}
          />

          {canAddTags && (
            <div className="Selects">
              <button
                onClick={() => handel_open_model(ModalEnum?.TAGS_ADD)}
                className="add_button"
              >
                {t("models.tags")} <FaPlus />
              </button>
            </div>
          )}
        </header>

        <Table />
        <DeleteModalForm />
        <AddModalForm />
        <EditModalForm />
      </Suspense>
    </div>
  );
};

export default TableHeader;
