import * as n from "react";
import c from "../../../classnames/index.mjs";
import M from "../../../rc-util/es/omit.mjs";
import { debounce as R } from "../../../throttle-debounce/esm/index.mjs";
import { isValidElement as h, cloneElement as w } from "../_util/reactNode.mjs";
import { devUseWarning as U } from "../_util/warning.mjs";
import "../config-provider/index.mjs";
import W from "./style/index.mjs";
import { ConfigContext as j } from "../config-provider/context.mjs";
var q = globalThis && globalThis.__rest || function(e, r) {
  var a = {};
  for (var t in e)
    Object.prototype.hasOwnProperty.call(e, t) && r.indexOf(t) < 0 && (a[t] = e[t]);
  if (e != null && typeof Object.getOwnPropertySymbols == "function")
    for (var o = 0, t = Object.getOwnPropertySymbols(e); o < t.length; o++)
      r.indexOf(t[o]) < 0 && Object.prototype.propertyIsEnumerable.call(e, t[o]) && (a[t[o]] = e[t[o]]);
  return a;
};
let u = null;
function A(e, r) {
  const {
    indicator: a
  } = r, t = `${e}-dot`;
  return a === null ? null : h(a) ? w(a, {
    className: c(a.props.className, t)
  }) : h(u) ? w(u, {
    className: c(u.props.className, t)
  }) : /* @__PURE__ */ n.createElement("span", {
    className: c(t, `${e}-dot-spin`)
  }, /* @__PURE__ */ n.createElement("i", {
    className: `${e}-dot-item`,
    key: 1
  }), /* @__PURE__ */ n.createElement("i", {
    className: `${e}-dot-item`,
    key: 2
  }), /* @__PURE__ */ n.createElement("i", {
    className: `${e}-dot-item`,
    key: 3
  }), /* @__PURE__ */ n.createElement("i", {
    className: `${e}-dot-item`,
    key: 4
  }));
}
function B(e, r) {
  return !!e && !!r && !isNaN(Number(r));
}
const g = (e) => {
  const {
    prefixCls: r,
    spinning: a = !0,
    delay: t = 0,
    className: o,
    rootClassName: x,
    size: v = "default",
    tip: p,
    wrapperClassName: P,
    style: _,
    children: f,
    fullscreen: m
  } = e, k = q(e, ["prefixCls", "spinning", "delay", "className", "rootClassName", "size", "tip", "wrapperClassName", "style", "children", "fullscreen"]), {
    getPrefixCls: V
  } = n.useContext(j), s = V("spin", r), [E, $, b] = W(s), [d, O] = n.useState(() => a && !B(a, t));
  n.useEffect(() => {
    if (a) {
      const i = R(t, () => {
        O(!0);
      });
      return i(), () => {
        var y;
        (y = i == null ? void 0 : i.cancel) === null || y === void 0 || y.call(i);
      };
    }
    O(!1);
  }, [t, a]);
  const N = n.useMemo(() => typeof f < "u" && !m, [f, m]);
  if (process.env.NODE_ENV !== "production") {
    const i = U("Spin");
    process.env.NODE_ENV !== "production" && i(!p || N, "usage", "`tip` only work in nest pattern.");
  }
  const {
    direction: D,
    spin: l
  } = n.useContext(j), I = c(s, l == null ? void 0 : l.className, {
    [`${s}-sm`]: v === "small",
    [`${s}-lg`]: v === "large",
    [`${s}-spinning`]: d,
    [`${s}-show-text`]: !!p,
    [`${s}-fullscreen`]: m,
    [`${s}-fullscreen-show`]: m && d,
    [`${s}-rtl`]: D === "rtl"
  }, o, x, $, b), z = c(`${s}-container`, {
    [`${s}-blur`]: d
  }), S = M(k, ["indicator"]), T = Object.assign(Object.assign({}, l == null ? void 0 : l.style), _), C = /* @__PURE__ */ n.createElement("div", Object.assign({}, S, {
    style: T,
    className: I,
    "aria-live": "polite",
    "aria-busy": d
  }), A(s, e), p && (N || m) ? /* @__PURE__ */ n.createElement("div", {
    className: `${s}-text`
  }, p) : null);
  return E(N ? /* @__PURE__ */ n.createElement("div", Object.assign({}, S, {
    className: c(`${s}-nested-loading`, P, $, b)
  }), d && /* @__PURE__ */ n.createElement("div", {
    key: "loading"
  }, C), /* @__PURE__ */ n.createElement("div", {
    className: z,
    key: "container"
  }, f)) : C);
};
g.setDefaultIndicator = (e) => {
  u = e;
};
process.env.NODE_ENV !== "production" && (g.displayName = "Spin");
const Y = g;
export {
  Y as default
};
