import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import React, { useCallback, useMemo, useState } from "react";
import { modals } from "./modal-components.js";
import { ModalContext } from "./modal-context.js";
export const ModalManager = (props) => {
    const { children } = props;
    const [modalProps, setModalProps] = useState();
    const [modalType, setModalType] = useState();
    const [open, setOpen] = useState(false);
    const showModal = useCallback((modalType, props) => {
        setOpen(true);
        setModalProps(props);
        setModalType(modalType);
    }, []);
    const closeModal = useCallback(() => {
        setOpen(false);
    }, []);
    const ModalComponent = modalType ? modals[modalType] : null;
    const value = useMemo(() => ({ showModal, closeModal }), [closeModal, showModal]);
    return (_jsxs(ModalContext.Provider, { value: value, children: [children, ModalComponent ? (_jsx(ModalComponent, { ...modalProps, onOpenChange: setOpen, open: open })) : null] }));
};
//# sourceMappingURL=modal-manager.js.map