import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { DialogContent, DialogHeader, Dialog, DialogTitle, DialogFooter } from "../dialog/dialog";
import { useMemo, useState } from "react";
import Button from "../button";
import { cn } from "../utils/css";
export const SimpleDialog = (props)=>{
    const [loading, setLoading] = useState(false);
    const actions = 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__*/ _jsx(Button, {
                id: props.cancelId,
                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__*/ _jsx(Button, {
                id: props.okId,
                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__*/ _jsx(DialogFooter, {
            className: cn(buttons.length > 1 ? "orderly-grid-cols-2" : "orderly-grid-cols-1"),
            children: buttons
        });
    }, [
        props.onCancel,
        props.onOk,
        loading,
        props.footer
    ]);
    return /*#__PURE__*/ _jsx(Dialog, {
        open: props.open,
        onOpenChange: props.onOpenChange,
        children: /*#__PURE__*/ _jsxs(DialogContent, {
            closable: props.closable,
            closeableSize: props.closeableSize,
            onOpenAutoFocus: (event)=>event.preventDefault(),
            className: cn("orderly-confirm-dialog", props.contentClassName),
            maxWidth: props.maxWidth,
            children: [
                props.title && /*#__PURE__*/ _jsx(DialogHeader, {
                    children: /*#__PURE__*/ _jsx(DialogTitle, {
                        children: props.title
                    })
                }),
                props.children,
                actions
            ]
        })
    });
};

//# sourceMappingURL=simpleDialog.js.map