"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "SimpleDialog", {
    enumerable: true,
    get: function() {
        return SimpleDialog;
    }
});
const _jsxruntime = require("react/jsx-runtime");
const _dialog = require("../dialog/dialog");
const _react = require("react");
const _button = /*#__PURE__*/ _interop_require_default(require("../button"));
const _css = require("../utils/css");
function _interop_require_default(obj) {
    return obj && obj.__esModule ? obj : {
        default: obj
    };
}
const SimpleDialog = (props)=>{
    const [loading, setLoading] = (0, _react.useState)(false);
    const actions = (0, _react.useMemo)(()=>{
        if (props.footer !== undefined) {
            return props.footer;
        }
        if (!props.onCancel && !props.onOk) {
            return null;
        }
        const buttons = [];
        if (typeof props.onCancel === "function") {
            buttons.push(/*#__PURE__*/ (0, _jsxruntime.jsx)(_button.default, {
                className: "orderly-confirm-dialog-cancal-button orderly-text-xs desktop:orderly-text-xs orderly-font-bold",
                type: "button",
                variant: "contained",
                color: "tertiary",
                onClick: props.onCancel,
                disabled: loading,
                fullWidth: true,
                children: "Cancel"
            }, "cancel"));
        }
        if (typeof props.onOk === "function") {
            buttons.push(/*#__PURE__*/ (0, _jsxruntime.jsx)(_button.default, {
                className: "orderly-confirm-dialog-ok-button orderly-text-xs desktop:orderly-text-xs orderly-font-bold",
                type: "button",
                disabled: loading,
                loading: loading,
                fullWidth: true,
                onClick: ()=>{
                    setLoading(true);
                    props.onOk?.().finally(()=>setLoading(false));
                },
                children: "OK"
            }, "ok"));
        }
        return /*#__PURE__*/ (0, _jsxruntime.jsx)(_dialog.DialogFooter, {
            className: (0, _css.cn)(buttons.length > 1 ? "orderly-grid-cols-2" : "orderly-grid-cols-1"),
            children: buttons
        });
    }, [
        props.onCancel,
        props.onOk,
        loading,
        props.footer
    ]);
    return /*#__PURE__*/ (0, _jsxruntime.jsx)(_dialog.Dialog, {
        open: props.open,
        onOpenChange: props.onOpenChange,
        children: /*#__PURE__*/ (0, _jsxruntime.jsxs)(_dialog.DialogContent, {
            closable: props.closable,
            closeableSize: props.closeableSize,
            onOpenAutoFocus: (event)=>event.preventDefault(),
            className: (0, _css.cn)("orderly-confirm-dialog", props.contentClassName),
            maxWidth: props.maxWidth,
            children: [
                props.title && /*#__PURE__*/ (0, _jsxruntime.jsx)(_dialog.DialogHeader, {
                    children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_dialog.DialogTitle, {
                        children: props.title
                    })
                }),
                props.children,
                actions
            ]
        })
    });
};

//# sourceMappingURL=simpleDialog.js.map