var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/modal/index.tsx
var modal_exports = {};
__export(modal_exports, {
  default: () => modal_default
});
module.exports = __toCommonJS(modal_exports);
var import_react = __toESM(require("react"));
var import_antd = require("antd");
var import_hooks = require("../_util/hooks");
var EhrModal = (props) => {
  const { onCancel, onOk, render, triggerDom, children, beforeShow, form, footer, ...rest } = props;
  const [visible, setVisible] = (0, import_hooks.useControllableValue)(props, { valuePropName: "open" in props ? "open" : "visible" });
  const isControllable = "visible" in props && props.visible !== void 0 || "open" in props && props.open !== void 0;
  const [loading, setLoading] = (0, import_react.useState)(false);
  const onClick = async () => {
    form && form.resetFields();
    if (typeof beforeShow === "function") {
      setVisible(await beforeShow() ?? true);
      return;
    }
    !isControllable && setVisible(true);
  };
  (0, import_react.useEffect)(() => {
    isControllable && visible && onClick();
  }, [isControllable, visible]);
  const _onOk = async () => {
    const fn = (values) => {
      let res = onOk == null ? void 0 : onOk(values);
      if (res && res.then) {
        setLoading(true);
        res.then(() => setVisible(false)).finally(() => setLoading(false));
      }
    };
    form ? form.validateFields().then((values) => {
      fn(values);
    }).catch((errorInfo) => {
      var _a;
      form.scrollToField((_a = errorInfo.errorFields[0]) == null ? void 0 : _a.name.toString());
    }) : fn();
  };
  const _onCancel = (e) => {
    onCancel && onCancel(e);
    !isControllable && setVisible(false);
  };
  const modalProps = {
    maskClosable: false,
    width: 620,
    destroyOnClose: true,
    confirmLoading: loading,
    ...rest,
    ...{ footer: typeof footer === "function" ? footer(_onCancel, _onOk) : footer },
    open: visible,
    onCancel: _onCancel,
    onOk: _onOk
  };
  return (0, import_hooks.useConfig)(
    /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, triggerDom && (0, import_react.cloneElement)(triggerDom, {
      ...triggerDom.props,
      onClick: (e) => {
        var _a, _b;
        !isControllable && onClick();
        (_b = (_a = triggerDom.props) == null ? void 0 : _a.onClick) == null ? void 0 : _b.call(_a, e);
      }
    }), /* @__PURE__ */ import_react.default.createElement(import_antd.Modal, { ...modalProps }, render ? render(_onCancel, _onOk) : children))
  );
};
var { info, success, error, warn, warning, confirm, destroyAll } = import_antd.Modal;
EhrModal.info = info;
EhrModal.success = success;
EhrModal.error = error;
EhrModal.warn = warn;
EhrModal.warning = warning;
EhrModal.confirm = confirm;
EhrModal.destroyAll = destroyAll;
var modal_default = EhrModal;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {});
