"use strict";
const React = require("react");
const debounce = require("../../../../../../lodash@4.17.21/node_modules/lodash/debounce.js");
const index$1 = require("../../icon/react-icon/IconLoading/index.js");
const classNames = require("../_util/classNames.js");
const index = require("../ConfigProvider/index.js");
const dotLoading = require("./dot-loading.js");
const useMergeProps = require("../_util/hooks/useMergeProps.js");
const emotionReactJsxRuntime_browser_esm = require("../../../../../../@emotion_react@11.10.4_3toe27fv7etiytxb5kxc7fxaw4/node_modules/@emotion/react/jsx-runtime/dist/emotion-react-jsx-runtime.browser.esm.js");
const _interopDefaultLegacy = (e) => e && typeof e === "object" && "default" in e ? e : { default: e };
const React__default = /* @__PURE__ */ _interopDefaultLegacy(React);
var __assign = globalThis && globalThis.__assign || function() {
  __assign = Object.assign || function(t) {
    for (var s, i = 1, n = arguments.length; i < n; i++) {
      s = arguments[i];
      for (var p in s)
        if (Object.prototype.hasOwnProperty.call(s, p))
          t[p] = s[p];
    }
    return t;
  };
  return __assign.apply(this, arguments);
};
var __rest = globalThis && globalThis.__rest || function(s, e) {
  var t = {};
  for (var p in s)
    if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
      t[p] = s[p];
  if (s != null && typeof Object.getOwnPropertySymbols === "function")
    for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
      if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
        t[p[i]] = s[p[i]];
    }
  return t;
};
var __read = globalThis && globalThis.__read || function(o, n) {
  var m = typeof Symbol === "function" && o[Symbol.iterator];
  if (!m)
    return o;
  var i = m.call(o), r, ar = [], e;
  try {
    while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
      ar.push(r.value);
  } catch (error) {
    e = {
      error
    };
  } finally {
    try {
      if (r && !r.done && (m = i["return"]))
        m.call(i);
    } finally {
      if (e)
        throw e.error;
    }
  }
  return ar;
};
function Spin(baseProps, ref) {
  var _a;
  var _b = React.useContext(index.ConfigContext), getPrefixCls = _b.getPrefixCls, componentConfig = _b.componentConfig;
  var props = useMergeProps(baseProps, {}, componentConfig === null || componentConfig === void 0 ? void 0 : componentConfig.Spin);
  var style = props.style, className = props.className, children = props.children, propLoading = props.loading, size = props.size, icon = props.icon, element = props.element, tip = props.tip, dot = props.dot, delay = props.delay, _c = props.block, block = _c === void 0 ? false : _c, rest = __rest(props, ["style", "className", "children", "loading", "size", "icon", "element", "tip", "dot", "delay", "block"]);
  var _d = __read(React.useState(delay ? false : propLoading), 2), loading = _d[0], setLoading = _d[1];
  var debouncedSetLoading = React.useCallback(debounce(setLoading, delay), [delay]);
  var _usedLoading = delay ? loading : propLoading;
  var prefixCls = getPrefixCls("spin");
  React.useEffect(function() {
    delay && debouncedSetLoading(propLoading);
    return function() {
      debouncedSetLoading && debouncedSetLoading.cancel();
    };
  }, [propLoading]);
  var loadingIcon = /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx("span", {
    className: prefixCls + "-icon",
    children: icon ? React__default.default.cloneElement(icon, {
      className: classNames(prefixCls.replace("-spin", "-icon") + "-loading"),
      style: {
        fontSize: size
      }
    }) : element || (dot ? /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx(dotLoading, {
      size
    }) : /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx(index$1, {
      style: {
        fontSize: size
      }
    }))
  });
  return /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx("div", {
    ...__assign({
      ref,
      className: classNames(prefixCls, (_a = {}, _a[prefixCls + "-block"] = block, _a[prefixCls + "-loading"] = _usedLoading, _a[prefixCls + "-with-tip"] = tip && !children, _a), className),
      style
    }, rest),
    children: children ? /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsxs(emotionReactJsxRuntime_browser_esm.Fragment, {
      children: [/* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx("div", {
        className: prefixCls + "-children",
        children
      }), _usedLoading && /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx("div", {
        className: prefixCls + "-loading-layer",
        style: {
          fontSize: size
        },
        children: /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsxs("span", {
          className: prefixCls + "-loading-layer-inner",
          children: [loadingIcon, tip ? /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx("div", {
            className: prefixCls + "-tip",
            children: tip
          }) : null]
        })
      })]
    }) : /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsxs(emotionReactJsxRuntime_browser_esm.Fragment, {
      children: [loadingIcon, tip ? /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx("div", {
        className: prefixCls + "-tip",
        children: tip
      }) : null]
    })
  });
}
var SpinComponent = React__default.default.forwardRef(Spin);
SpinComponent.displayName = "Spin";
const Spin$1 = SpinComponent;
module.exports = Spin$1;
//# sourceMappingURL=index.js.map
