
import React, { useMemo } from "react";
import { useTranslation } from "react-i18next";
import Actions from "../../Components/Ui/tables/Actions";
import { useDeleteContact } from "../../api/Contact";
import ColumnsImage from "../../Components/Columns/ColumnsImage";

function fnDelete(props :any ){}

const useTableColumns :any = () => {
  const [t] = useTranslation();
  const deleteMutation = useDeleteContact()

  return useMemo(
    () => [
 
      {
        name: t("title"),
        sortable: false,
        center: "true",
        cell: (row:any) => row?.title
      },
      {
        name: t("sub_title"),
        sortable: false,
        center: "true",
        cell: (row:any) => row?.sub_title
      },
      {
        name: t("description"),
        sortable: false,
        center: "true",
        cell: (row: any) => {
            const words = row.description.split(' ');
            const firstTenWords = words.slice(0, 10).join(' ');
            const result = words.length > 10 ? firstTenWords + '...' : firstTenWords;
            return result;
        },
      },
      {
        name: t("direction"),
        sortable: false,
        center: "true",
        cell: (row:any) => row?.direction == true? "ltr" : "rtl"
      },
      {
        name: t("is_have_button"),
        sortable: false,
        center: "true",
        cell: (row:any) => row?.is_have_button == true? "1" : "0"
      },
      {
        name: t("image"),
        center: "true",
        cell: (row: any) => {
          return (
            <ColumnsImage src={row?.image} />
          )
        }
      },
      {
        name: "#",
        sortable: false,
        center: "true",
        cell: (row) => (
            <Actions

            // importnat to return the row in on Edit Function to store in objectToEdit That Upper in Edit Modal 
              onEdit={() => row}
              onView={()=>{}}
              objectToEdit={row}
              showEdit={true}
              showView={false}
              onDelete={() => deleteMutation.mutate({ id: row.id })}
            />
        ),
      },
    ],
    [t]
  );
};

export default useTableColumns;

