import { modals } from "@mantine/modals";
import { useServicesContext } from "@/app/services/contexts/ServicesContext";
import { ServiceCategorySchema } from "@/lib/client";

const useCategoriesActions = () => {
    const { categoriesCrud } = useServicesContext();

    const onChangeCategory = (category: ServiceCategorySchema) => {
        modals.openContextModal({
            modal: "serviceCategoryEditorModal",
            title: "Создание категории",
            withCloseButton: false,
            innerProps: {
                onChange: value => categoriesCrud.onUpdate(category.id, value),
                entity: category,
                isEditing: true,
            },
        });
    };

    const onCreateCategory = () => {
        modals.openContextModal({
            modal: "serviceCategoryEditorModal",
            title: "Создание категории",
            withCloseButton: false,
            innerProps: {
                onCreate: categoriesCrud.onCreate,
                isEditing: false,
            },
        });
    };

    return {
        onCreateCategory,
        onChangeCategory,
    };
};

export default useCategoriesActions;
