"use client";
import { jsx } from "react/jsx-runtime";
import { useCallback, useMemo, useState } from "react";
import ui_modal from "../ui/modal.js";
function useModal() {
    const [modalContent, setModalContent] = useState(null);
    const onClose = useCallback(()=>{
        setModalContent(null);
    }, []);
    const modal = useMemo(()=>{
        if (null === modalContent) return null;
        const { title, content, closeOnClickOutside } = modalContent;
        return /*#__PURE__*/ jsx(ui_modal, {
            onClose: onClose,
            title: title,
            closeOnClickOutside: closeOnClickOutside,
            children: content
        });
    }, [
        modalContent,
        onClose
    ]);
    const showModal = useCallback((title, getContent, closeOnClickOutside = false)=>{
        setModalContent({
            closeOnClickOutside,
            content: getContent(onClose),
            title
        });
    }, [
        onClose
    ]);
    return [
        modal,
        showModal
    ];
}
export default useModal;
