import * as a from "react";
import j from "../../../@ant-design/icons/es/icons/CloseOutlined.mjs";
import h from "../../../classnames/index.mjs";
import k from "../../../rc-notification/es/hooks/useNotification.mjs";
import I from "../../../rc-notification/es/NotificationProvider.mjs";
import { devUseWarning as S } from "../_util/warning.mjs";
import "../config-provider/index.mjs";
import { PureContent as _ } from "./PurePanel.mjs";
import R from "./style/index.mjs";
import { wrapPromiseFn as $, getMotion as A } from "./util.mjs";
import M from "../config-provider/hooks/useCSSVarCls.mjs";
import { ConfigContext as T } from "../config-provider/context.mjs";
var D = globalThis && globalThis.__rest || function(t, n) {
  var s = {};
  for (var e in t)
    Object.prototype.hasOwnProperty.call(t, e) && n.indexOf(e) < 0 && (s[e] = t[e]);
  if (t != null && typeof Object.getOwnPropertySymbols == "function")
    for (var o = 0, e = Object.getOwnPropertySymbols(t); o < e.length; o++)
      n.indexOf(e[o]) < 0 && Object.prototype.propertyIsEnumerable.call(t, e[o]) && (s[e[o]] = t[e[o]]);
  return s;
};
const F = 8, U = 3, V = (t) => {
  let {
    children: n,
    prefixCls: s
  } = t;
  const e = M(s), [o, p, C] = R(s, e);
  return o(/* @__PURE__ */ a.createElement(I, {
    classNames: {
      list: h(p, C, e)
    }
  }, n));
}, H = (t, n) => {
  let {
    prefixCls: s,
    key: e
  } = n;
  return /* @__PURE__ */ a.createElement(V, {
    prefixCls: s,
    key: e
  }, t);
}, L = /* @__PURE__ */ a.forwardRef((t, n) => {
  const {
    top: s,
    prefixCls: e,
    getContainer: o,
    maxCount: p,
    duration: C = U,
    rtl: v,
    transitionName: E,
    onAllRemoved: l
  } = t, {
    getPrefixCls: r,
    getPopupContainer: i,
    message: c
  } = a.useContext(T), f = e || r("message"), u = () => ({
    left: "50%",
    transform: "translateX(-50%)",
    top: s ?? F
  }), d = () => h({
    [`${f}-rtl`]: v
  }), m = () => A(f, E), g = /* @__PURE__ */ a.createElement("span", {
    className: `${f}-close-x`
  }, /* @__PURE__ */ a.createElement(j, {
    className: `${f}-close-icon`
  })), [b, x] = k({
    prefixCls: f,
    style: u,
    className: d,
    motion: m,
    closable: !1,
    closeIcon: g,
    duration: C,
    getContainer: () => (o == null ? void 0 : o()) || (i == null ? void 0 : i()) || document.body,
    maxCount: p,
    onAllRemoved: l,
    renderNotifications: H
  });
  return a.useImperativeHandle(n, () => Object.assign(Object.assign({}, b), {
    prefixCls: f,
    message: c
  })), x;
});
let P = 0;
function W(t) {
  const n = a.useRef(null), s = S("Message");
  return [a.useMemo(() => {
    const o = (l) => {
      var r;
      (r = n.current) === null || r === void 0 || r.close(l);
    }, p = (l) => {
      if (!n.current) {
        process.env.NODE_ENV !== "production" && s(!1, "usage", "You are calling notice in render which will break in React 18 concurrent mode. Please trigger in effect instead.");
        const O = () => {
        };
        return O.then = () => {
        }, O;
      }
      const {
        open: r,
        prefixCls: i,
        message: c
      } = n.current, f = `${i}-notice`, {
        content: u,
        icon: d,
        type: m,
        key: g,
        className: b,
        style: x,
        onClose: N
      } = l, w = D(l, ["content", "icon", "type", "key", "className", "style", "onClose"]);
      let y = g;
      return y == null && (P += 1, y = `antd-message-${P}`), $((O) => (r(Object.assign(Object.assign({}, w), {
        key: y,
        content: /* @__PURE__ */ a.createElement(_, {
          prefixCls: i,
          type: m,
          icon: d
        }, u),
        placement: "top",
        className: h(m && `${f}-${m}`, b, c == null ? void 0 : c.className),
        style: Object.assign(Object.assign({}, c == null ? void 0 : c.style), x),
        onClose: () => {
          N == null || N(), O();
        }
      })), () => {
        o(y);
      }));
    }, v = {
      open: p,
      destroy: (l) => {
        var r;
        l !== void 0 ? o(l) : (r = n.current) === null || r === void 0 || r.destroy();
      }
    };
    return ["info", "success", "warning", "error", "loading"].forEach((l) => {
      const r = (i, c, f) => {
        let u;
        i && typeof i == "object" && "content" in i ? u = i : u = {
          content: i
        };
        let d, m;
        typeof c == "function" ? m = c : (d = c, m = f);
        const g = Object.assign(Object.assign({
          onClose: m,
          duration: d
        }, u), {
          type: l
        });
        return p(g);
      };
      v[l] = r;
    }), v;
  }, []), /* @__PURE__ */ a.createElement(L, Object.assign({
    key: "message-holder"
  }, t, {
    ref: n
  }))];
}
function te(t) {
  return W(t);
}
export {
  te as default,
  W as useInternalMessage
};
