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/hooks/useModalEnhanced.ts
var useModalEnhanced_exports = {};
__export(useModalEnhanced_exports, {
  default: () => useModalEnhanced_default
});
module.exports = __toCommonJS(useModalEnhanced_exports);
var import_react = __toESM(require("react"));
var import_context = require("../context");
var import_util = require("../util");
var import_useBoolean = __toESM(require("./useBoolean"));
var import_useLatestFunc = __toESM(require("./useLatestFunc"));
function useModalEnhanced(props = {}) {
  const { onClick, actionRef: actionRefProp, defaultOpen } = props;
  const [visible, { setTrue: open, setFalse }] = (0, import_useBoolean.default)(defaultOpen);
  const close = (0, import_useLatestFunc.default)((callbackName, ...restArgs) => {
    setFalse();
    if (callbackName && (0, import_util.has)(props, callbackName)) {
      props[callbackName](...restArgs);
    }
  });
  const actionRef = import_react.default.useRef({ open, close });
  const { triggerProps, contentProps } = (0, import_context.useEasyAntdModal)();
  const mergedTrigger = props[triggerProps];
  const mergedContent = props[contentProps];
  import_react.default.useImperativeHandle(actionRefProp, () => actionRef.current);
  const handleClick = (event) => {
    if (onClick)
      return onClick(event, actionRef.current);
    return open();
  };
  let trigger = mergedTrigger;
  if (import_react.default.isValidElement(mergedTrigger))
    trigger = import_react.default.cloneElement(mergedTrigger, { onClick: handleClick });
  let contentNode = mergedContent;
  if ((0, import_util.isElement)(contentNode) && !(0, import_util.isDOMTypeElement)(contentNode)) {
    contentNode = import_react.default.cloneElement(contentNode, {
      enhancedAction: actionRef.current
    });
  } else if (typeof mergedContent === "function") {
    contentNode = mergedContent({
      enhancedAction: actionRef.current
    });
  }
  const contextHolder = { trigger, content: contentNode };
  const action = { open, close };
  const resetProps = (0, import_util.omit)(props, [
    "defaultOpen",
    "onClick",
    "actionRef",
    "content",
    "trigger",
    "children"
  ]);
  return [visible, action, contextHolder, resetProps];
}
var useModalEnhanced_default = useModalEnhanced;
