import { modals } from "@mantine/modals";
import { useDealTagsContext } from "@/drawers/common/ProjectEditorDrawer/tabs/TagsTab/contexts/DealTagsContext";
import { DealTagSchema } from "@/lib/client";

const useDealTagActions = () => {
    const { dealTagsCrud } = useDealTagsContext();

    const onChangeClick = (tag: DealTagSchema) => {
        modals.openContextModal({
            modal: "dealTagModal",
            innerProps: {
                entity: tag,
                onChange: data => dealTagsCrud.onUpdate(tag.id, data),
                isEditing: true,
            },
            withCloseButton: false,
        });
    };

    const onCreateClick = () => {
        modals.openContextModal({
            modal: "dealTagModal",
            innerProps: {
                onCreate: dealTagsCrud.onCreate,
                isEditing: false,
            },
            withCloseButton: false,
        });
    };

    return {
        onChangeClick,
        onCreateClick,
    };
};

export default useDealTagActions;
