import { TableColumnsType } from "antd";
import { StudentPackage } from "../../types/studentPackage";
import { FaPlus } from "react-icons/fa";
import useModalHandler from "../../utils/useModalHandler";
import { ModalEnum } from "../../enums/Model";
import { useObjectToEdit } from "../../zustand/ObjectToEditState";
import { useTranslation } from "react-i18next";
import { ABILITIES_ENUM } from "../../enums/abilities";
import { useNavigate } from "react-router-dom";
import {
  canAddStudentPackage,
  canDeleteStudentPackage,
  canEditStudentPackage,
  canShowStudentPackage,
} from "../../utils/hasAbilityFn";
import ActionButtons from "../../Components/Table/ActionButtons";
import ColumnsImage from "../../Components/Columns/ColumnsImage";

export const useColumns = () => {
  const { handel_open_model } = useModalHandler();

  const { setObjectToEdit } = useObjectToEdit((state) => state);
  const navigate = useNavigate();

  const handelShow = (record: StudentPackage) => {
    navigate(`${record?.id}`);
  };

  const handelDelete = (data: StudentPackage) => {
    setObjectToEdit(data);
    handel_open_model(ModalEnum?.STUDENT_PACKAGE_DELETE);
  };

  const handleEdit = (record: StudentPackage) => {
    setObjectToEdit(record);
    handel_open_model(ModalEnum?.STUDENT_PACKAGE_EDIT);
  };
  const [t] = useTranslation();

  const columns: TableColumnsType<StudentPackage> = [
    {
      title: t("columns.id"),
      dataIndex: "id",
      key: "id",
      align: "center",
      render: (_text, record) => record?.id,
    },
    {
      title: `${t("columns.name")}`,
      dataIndex: "name",
      key: "name",
      align: "center",
      render: (_text, record) => record?.name,
    },
    {
      title: canAddStudentPackage ? (
        <button
          onClick={() => handel_open_model(ModalEnum?.STUDENT_PACKAGE_ADD)}
          className="add_button"
        >
          {t("practical.add")} {t("models.StudentPackage")} <FaPlus />
        </button>
      ) : (
        ""
      ),

      key: "actions",
      align: "end",
      width: "25vw",
      render: (_text, record, index) => {
        return (
          <ActionButtons
            canDelete={canDeleteStudentPackage}
            canEdit={canEditStudentPackage}
            canShow={canShowStudentPackage}
            index={index}
            onDelete={() => handelDelete(record)}
            onEdit={() => handleEdit(record)}
            onShow={() => handelShow(record)}
          />
        );
      },
    },
  ];

  return columns;
};
