import P from "../../../../@babel/runtime/helpers/esm/toConsumableArray.mjs";
import * as c from "react";
import "../../config-provider/index.mjs";
import h from "../../locale/en_US.mjs";
import k from "../../locale/useLocale.mjs";
import w from "../ConfirmDialog.mjs";
import { ConfigContext as M } from "../../config-provider/context.mjs";
var S = globalThis && globalThis.__rest || function(t, s) {
  var a = {};
  for (var o in t)
    Object.prototype.hasOwnProperty.call(t, o) && s.indexOf(o) < 0 && (a[o] = t[o]);
  if (t != null && typeof Object.getOwnPropertySymbols == "function")
    for (var n = 0, o = Object.getOwnPropertySymbols(t); n < o.length; n++)
      s.indexOf(o[n]) < 0 && Object.prototype.propertyIsEnumerable.call(t, o[n]) && (a[o[n]] = t[o[n]]);
  return a;
};
const A = (t, s) => {
  var a, {
    afterClose: o,
    config: n
  } = t, u = S(t, ["afterClose", "config"]);
  const [C, g] = c.useState(!0), [e, v] = c.useState(n), {
    direction: x,
    getPrefixCls: d
  } = c.useContext(M), O = d("modal"), b = d(), y = () => {
    var l;
    o(), (l = e.afterClose) === null || l === void 0 || l.call(e);
  }, p = function() {
    g(!1);
    for (var l = arguments.length, i = new Array(l), f = 0; f < l; f++)
      i[f] = arguments[f];
    const j = i.some((m) => m && m.triggerCancel);
    e.onCancel && j && e.onCancel.apply(e, [() => {
    }].concat(P(i.slice(1))));
  };
  c.useImperativeHandle(s, () => ({
    destroy: p,
    update: (l) => {
      v((i) => Object.assign(Object.assign({}, i), l));
    }
  }));
  const T = (a = e.okCancel) !== null && a !== void 0 ? a : e.type === "confirm", [r] = k("Modal", h.Modal);
  return /* @__PURE__ */ c.createElement(w, Object.assign({
    prefixCls: O,
    rootPrefixCls: b
  }, e, {
    close: p,
    open: C,
    afterClose: y,
    okText: e.okText || (T ? r == null ? void 0 : r.okText : r == null ? void 0 : r.justOkText),
    direction: e.direction || x,
    cancelText: e.cancelText || (r == null ? void 0 : r.cancelText)
  }, u));
}, D = /* @__PURE__ */ c.forwardRef(A);
export {
  D as default
};
