import y from "../../../rc-util/es/hooks/useState.mjs";
import * as l from "react";
import O from "../button/button.mjs";
import { convertLegacyProps as P } from "../button/buttonHelpers.mjs";
function a(o) {
  return !!(o && o.then);
}
const x = (o) => {
  const {
    type: m,
    children: d,
    prefixCls: p,
    buttonProps: v,
    close: u,
    autoFocus: g,
    emitEvent: h,
    isSilent: s,
    quitOnNullishReturnValue: R,
    actionFn: r
  } = o, n = l.useRef(!1), f = l.useRef(null), [C, c] = y(!1), i = function() {
    u == null || u.apply(void 0, arguments);
  };
  l.useEffect(() => {
    let t = null;
    return g && (t = setTimeout(() => {
      var e;
      (e = f.current) === null || e === void 0 || e.focus();
    })), () => {
      t && clearTimeout(t);
    };
  }, []);
  const b = (t) => {
    a(t) && (c(!0), t.then(function() {
      c(!1, !0), i.apply(void 0, arguments), n.current = !1;
    }, (e) => {
      if (c(!1, !0), n.current = !1, !(s != null && s()))
        return Promise.reject(e);
    }));
  }, k = (t) => {
    if (n.current)
      return;
    if (n.current = !0, !r) {
      i();
      return;
    }
    let e;
    if (h) {
      if (e = r(t), R && !a(e)) {
        n.current = !1, i(t);
        return;
      }
    } else if (r.length)
      e = r(u), n.current = !1;
    else if (e = r(), !e) {
      i();
      return;
    }
    b(e);
  };
  return /* @__PURE__ */ l.createElement(O, Object.assign({}, P(m), {
    onClick: k,
    loading: C,
    prefixCls: p
  }, v, {
    ref: f
  }), d);
}, T = x;
export {
  T as default
};
