import { useColumns } from "./useTableColumns";
import React, { useEffect } from "react";
import DataTable from "../../Layout/Dashboard/Table/DataTable";
import { useGetAllUnit } from "../../api/unit";
import { useParams } from "react-router-dom";
import { ParamsEnum } from "../../enums/params";
import { useObjectToEdit } from "../../zustand/ObjectToEditState";

const App: React.FC = () => {
  const { subject_id } = useParams<ParamsEnum>();
  const response = useGetAllUnit({ subject_id: subject_id, pagination: true });
  const { setOldObjectToEdit } = useObjectToEdit();
  // console.log(response?.data?.data, "response?.data");
  const data = response?.data?.data;
  const lastElement =
    response?.data?.data && response?.data?.data[data?.length - 1];
  // console.log(lastElement);

  useEffect(() => {
    if (lastElement) {
      setOldObjectToEdit(lastElement);
    }
  }, [lastElement]);

  return <DataTable response={response} useColumns={useColumns} />;
};

export default App;
