import { FC } from "react";
import { IconEdit, IconTrash } from "@tabler/icons-react";
import { Flex } from "@mantine/core";
import { modals } from "@mantine/modals";
import ActionIconWithTip from "@/components/ui/ActionIconWithTip/ActionIconWithTip";
import { DealProductSchema } from "@/lib/client";
import { useFulfillmentBaseContext } from "@/modules/dealModularEditorTabs/FulfillmentBase/shared/contexts/FulfillmentBaseContext";

type Props = {
    dealProduct: DealProductSchema;
};

const ProductViewActions: FC<Props> = ({ dealProduct }) => {
    const { dealProductsCrud, dealProductsList, productsCrud } =
        useFulfillmentBaseContext();

    const onProductEditClick = () => {
        modals.openContextModal({
            modal: "productEditorModal",
            title: "Редактирование товара",
            withCloseButton: false,
            innerProps: {
                onChange: values =>
                    productsCrud.onUpdate(
                        dealProduct.productId,
                        values,
                        dealProductsList.refetch
                    ),
                entity: dealProduct.product,
                isEditing: true,
            },
        });
    };

    return (
        <Flex
            mt={"auto"}
            ml={"auto"}
            gap={"sm"}>
            {/*<Tooltip*/}
            {/*    onClick={onPrintBarcodeClick}*/}
            {/*    label="Печать штрихкода">*/}
            {/*    <ActionIcon variant={"default"}>*/}
            {/*        <IconBarcode />*/}
            {/*    </ActionIcon>*/}
            {/*</Tooltip>*/}
            <ActionIconWithTip
                onClick={onProductEditClick}
                tipLabel="Редактировать товар">
                <IconEdit />
            </ActionIconWithTip>
            <ActionIconWithTip
                onClick={() => dealProductsCrud.onDelete(dealProduct)}
                tipLabel="Удалить товар">
                <IconTrash />
            </ActionIconWithTip>
        </Flex>
    );
};

export default ProductViewActions;
