'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var vue = require('vue');
var lodashEs = require('lodash-es');
require('../../../utils/index.cjs');
var useConfigInject = require('../../config-provider/src/hooks/useConfigInject.cjs');
var index = require('../style/index.cjs');
var props = require('./props.cjs');
var initDefaultProps = require('../../../utils/vue/initDefaultProps.cjs');
var props$1 = require('../../../utils/vue/props.cjs');

let defaultIndicator = null;
function shouldDelay(spinning, delay) {
  return !!spinning && !!delay && !Number.isNaN(Number(delay));
}
function setDefaultIndicator(Content) {
  const Indicator = Content.indicator;
  defaultIndicator = typeof Indicator === "function" ? Indicator : () => vue.createVNode(Indicator, null, null);
}
var ASpin = /* @__PURE__ */ vue.defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "ASpin",
  inheritAttrs: false,
  props: initDefaultProps.initDefaultProps(props.spinProps(), {
    size: "default",
    spinning: true,
    wrapperClassName: ""
  }),
  setDefaultIndicator,
  setup(props, {
    attrs,
    slots
  }) {
    const {
      prefixCls,
      size,
      direction
    } = useConfigInject.default("spin", props);
    const [wrapSSR, hashId] = index.default(prefixCls);
    const sSpinning = vue.shallowRef(props.spinning && !shouldDelay(props.spinning, props.delay));
    let updateSpinning;
    vue.watch([() => props.spinning, () => props.delay], () => {
      updateSpinning == null ? void 0 : updateSpinning.cancel();
      updateSpinning = lodashEs.debounce(() => {
        sSpinning.value = props.spinning;
      }, props.delay);
      updateSpinning == null ? void 0 : updateSpinning();
    }, {
      immediate: true,
      flush: "post"
    });
    vue.onBeforeUnmount(() => {
      updateSpinning == null ? void 0 : updateSpinning.cancel();
    });
    return () => {
      var _a, _b;
      const {
        class: cls,
        ...divProps
      } = attrs;
      const {
        tip = (_a = slots.tip) == null ? void 0 : _a.call(slots)
      } = props;
      const children = (_b = slots.default) == null ? void 0 : _b.call(slots);
      const spinClassName = {
        [hashId.value]: true,
        [prefixCls.value]: true,
        [`${prefixCls.value}-sm`]: size.value === "small",
        [`${prefixCls.value}-lg`]: size.value === "large",
        [`${prefixCls.value}-spinning`]: sSpinning.value,
        [`${prefixCls.value}-show-text`]: !!tip,
        [`${prefixCls.value}-rtl`]: direction.value === "rtl",
        [cls]: !!cls
      };
      function renderIndicator(prefixCls2) {
        const dotClassName = `${prefixCls2}-dot`;
        let indicator = props$1.getPropsSlot(slots, props, "indicator");
        if (indicator === null)
          return null;
        if (Array.isArray(indicator))
          indicator = indicator.length === 1 ? indicator[0] : indicator;
        if (vue.isVNode(indicator))
          return vue.cloneVNode(indicator, {
            class: dotClassName
          });
        if (defaultIndicator && vue.isVNode(defaultIndicator()))
          return vue.cloneVNode(defaultIndicator(), {
            class: dotClassName
          });
        return vue.createVNode("span", {
          "class": `${dotClassName} ${prefixCls2}-dot-spin`
        }, [vue.createVNode("i", {
          "class": `${prefixCls2}-dot-item`
        }, null), vue.createVNode("i", {
          "class": `${prefixCls2}-dot-item`
        }, null), vue.createVNode("i", {
          "class": `${prefixCls2}-dot-item`
        }, null), vue.createVNode("i", {
          "class": `${prefixCls2}-dot-item`
        }, null)]);
      }
      const spinElement = vue.createVNode("div", {
        ...divProps,
        "class": spinClassName,
        "aria-live": "polite",
        "aria-busy": sSpinning.value
      }, [renderIndicator(prefixCls.value), tip ? vue.createVNode("div", {
        "class": `${prefixCls.value}-text`
      }, [tip]) : null]);
      if (children && props$1.filterEmpty(children).length) {
        const containerClassName = {
          [`${prefixCls.value}-container`]: true,
          [`${prefixCls.value}-blur`]: sSpinning.value
        };
        return wrapSSR(vue.createVNode("div", {
          "class": [`${prefixCls.value}-nested-loading`, props.wrapperClassName, hashId.value]
        }, [sSpinning.value && vue.createVNode("div", {
          "key": "loading"
        }, [spinElement]), vue.createVNode("div", {
          "class": containerClassName,
          "key": "container"
        }, [children])]));
      }
      return wrapSSR(spinElement);
    };
  }
});

exports.default = ASpin;
exports.setDefaultIndicator = setDefaultIndicator;
//# sourceMappingURL=Spin.cjs.map
