import { CRUDTableProps } from "../../../../types/CRUDTable.tsx";
import { ServicePriceCategorySchema } from "../../../../client";
import { FC } from "react";
import { BaseTable } from "../../../../components/BaseTable/BaseTable.tsx";
import useServicePriceCategoryTableColumns from "./columns.tsx";
import { MRT_TableOptions } from "mantine-react-table";
import { ActionIcon, Flex, Tooltip } from "@mantine/core";
import { IconEdit, IconTrash } from "@tabler/icons-react";

type Props = CRUDTableProps<ServicePriceCategorySchema>;

const ServicePriceCategoryTable: FC<Props> = ({
    items,
    onChange,
    onDelete,
}) => {
    const columns = useServicePriceCategoryTableColumns();
    return (
        <BaseTable
            data={items}
            columns={columns}
            restProps={
                {
                    enableRowActions: true,
                    renderRowActions: ({ row }) => (
                        <Flex gap="md">
                            <Tooltip label="Редактировать">
                                <ActionIcon
                                    onClick={() =>
                                        onChange && onChange(row.original)
                                    }
                                    variant={"default"}>
                                    <IconEdit />
                                </ActionIcon>
                            </Tooltip>
                            <Tooltip label="Удалить">
                                <ActionIcon
                                    onClick={() =>
                                        onDelete && onDelete(row.original)
                                    }
                                    variant={"default"}>
                                    <IconTrash />
                                </ActionIcon>
                            </Tooltip>
                        </Flex>
                    ),
                } as MRT_TableOptions<ServicePriceCategorySchema>
            }
        />
    );
};

export default ServicePriceCategoryTable;
