
import React, { useMemo } from "react";
import { useTranslation } from "react-i18next";
import Actions from "../../Components/Ui/tables/Actions";
import ColumnsImage from "../../Components/Columns/ColumnsImage";
import { useDeleteCategories } from "../../api/Categories";
import { useNavigate } from "react-router-dom";


const useTableColumns :any = () => {
  const [t] = useTranslation();
  const deleteMutation = useDeleteCategories()
  const navigate = useNavigate()
  const language = localStorage.getItem("language") ?? "en"

  return useMemo(
    () => [
 
      {
        name: t("id"),
        sortable: true, // Enable sorting for id column
        center: true,
        selector: (row: any) => row.id, // Specify selector function for sorting
      },      {
        name: t("name"),
        sortable: false,
        center: "true",
        cell: (row:any) => row?.name[language]
      },
      {
        name: t("image"),
        sortable: false,
        center: "true",
        cell: (row:any) =>  {
          let str = row?.photo;
          str =  str?.replace(`public`, "/storage") ?? ""; 
          return <ColumnsImage src={str} />
        }
        
      },
      {
        name: t("parent_id"),
        sortable: false,
        center: "true",
        cell: (row:any) => row?.parent_id
      },
      {
        name: t("product_count"),
        sortable: false,
        center: "true",
        cell: (row:any) => row?.product_count
      },
      {
        name: "#",
        sortable: false,
        center: true,
        cell: (row:any) => (
          <Actions
            objectToEdit={row}
            showEdit
            onEdit={()=> navigate(`/categories/${row.id}`) }
            showView={false}
            onDelete={() => deleteMutation.mutate({ id: row.id })}
          />
        ),
      },

    
    ],
    [t]
  );
};

export default useTableColumns;

