
import React, { useMemo } from "react";
import { useTranslation } from "react-i18next";
import Actions from "../../Components/Ui/tables/Actions";
import ColumnsImage from "../../Components/Columns/ColumnsImage";
import { useNavigate } from "react-router-dom";
import { useDeleteCoupon } from "../../api/Coupon";
import { MdEmail } from "react-icons/md";
import { useModalState } from "../../zustand/Modal";

function fnDelete(props :any ){}

const useTableColumns :any = () => {
  const [t] = useTranslation();
  const deleteMutation = useDeleteCoupon()
  const navigate = useNavigate()
  const {setIsOpen} = useModalState(state=>state)
    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
      },
      {
        name: t("discount_type"),
        sortable: false,
        center: "true",
        cell: (row:any) => row?.discount_type
      },
      {
        name: t("coupon_type"),
        sortable: false,
        center: "true",
        cell: (row:any) => row?.coupon_type
      },
      {
        name: t("code"),
        sortable: false,
        center: "true",
        cell: (row:any) => row?.code
      },
      {
        name: t("coupon_value"),
        sortable: false,
        center: "true",
        cell: (row:any) => {
          const rowvalue = row?.discount_type === "percentage" ?  "%" : ""
          return (
            rowvalue + row?.coupon_value
          )
        }
      },
      {
        name: "#",
        sortable: false,
        center: true,
        cell: (row:any) => (
          <Actions
            objectToEdit={row}
            showEdit
            onEdit={()=> navigate(`/coupon/${row.id}`) }
            showView={false}
            onDelete={() => deleteMutation.mutate({ id: row.id })}
          >  
          </Actions>
        ),
      },

    ],
    [t]
  );
};

export default useTableColumns;

