import { jsx as _jsx } from "react/jsx-runtime";
import { SimpleDialog } from "../../dialog/simpleDialog";
import { useModal } from "../../modal";
import { create } from "../../modal/modalHelper";
import { modalActions } from "../../modal/modalContext";
import { DialogBody } from "../../dialog";
const ConfirmDialog = create((props)=>{
    const { visible, hide, resolve, reject, onOpenChange } = useModal();
    return /*#__PURE__*/ _jsx(SimpleDialog, {
        open: visible,
        title: props.title,
        contentClassName: props.contentClassName,
        maxWidth: props.maxWidth,
        closable: true,
        closeableSize: props.closeableSize,
        onOpenChange: (open)=>{
            if (!open) {
                reject();
            }
            onOpenChange(open);
        },
        onOk: ()=>{
            return Promise.resolve().then(()=>{
                if (typeof props.onOk === "function") {
                    return props.onOk();
                }
                return true;
            }).then((data)=>{
                resolve(data);
                hide();
            });
        },
        onCancel: typeof props.onCancel !== "undefined" ? ()=>{
            return props.onCancel?.().then((data)=>data, (reason)=>{
                reject(reason);
            }).finally(()=>hide());
        } : undefined,
        footer: props.footer,
        children: /*#__PURE__*/ _jsx(DialogBody, {
            children: /*#__PURE__*/ _jsx("div", {
                className: "orderly-py-5 orderly-text-xs",
                children: props.content
            })
        })
    });
});
export const confirm = (props)=>{
    return modalActions.show(ConfirmDialog, props);
};

//# sourceMappingURL=confirm.js.map