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

const useServicesActions = () => {
    const { servicesCrud } = useServicesContext();

    const onChangeService = (service: ServiceSchema) => {
        modals.openContextModal({
            modal: "serviceEditorModal",
            title: "Редактирование услуги",
            withCloseButton: false,
            innerProps: {
                onChange: value => servicesCrud.onUpdate(service.id, value),
                entity: service,
                isEditing: true,
            },
        });
    };

    const onCreateService = () => {
        modals.openContextModal({
            modal: "serviceEditorModal",
            title: "Создание услуги",
            withCloseButton: false,
            innerProps: {
                onCreate: servicesCrud.onCreate,
                isEditing: false,
            },
        });
    };

    return {
        onCreateService,
        onChangeService,
    };
};

export default useServicesActions;
