import { FC } from "react";
import { IconArrowRight, IconEdit, IconTrash } from "@tabler/icons-react";
import { Center, Flex } from "@mantine/core";
import ActionIconWithTip from "@/components/ui/ActionIconWithTip/ActionIconWithTip";
import { AttributeSchema } from "@/lib/client";

type Props = {
    attribute: AttributeSchema;
    onUpdate: (attribute: AttributeSchema) => void;
    onDelete: (attribute: AttributeSchema) => void;
    addAttributeToModule?: (attribute: AttributeSchema) => void;
};

const AttributeTableActions: FC<Props> = ({
    attribute,
    onUpdate,
    onDelete,
    addAttributeToModule,
}) => {
    return (
        <Center>
            <Flex gap={"xs"}>
                <ActionIconWithTip
                    onClick={() => onUpdate(attribute)}
                    disabled={attribute.isBuiltIn}
                    tipLabel={"Редактировать"}>
                    <IconEdit />
                </ActionIconWithTip>
                <ActionIconWithTip
                    onClick={() => onDelete(attribute)}
                    disabled={attribute.isBuiltIn}
                    tipLabel={"Удалить"}>
                    <IconTrash />
                </ActionIconWithTip>
                {addAttributeToModule && (
                    <ActionIconWithTip
                        onClick={() => addAttributeToModule(attribute)}
                        tipLabel={"Добавить в модуль"}>
                        <IconArrowRight />
                    </ActionIconWithTip>
                )}
            </Flex>
        </Center>
    );
};

export default AttributeTableActions;
