/**
 * ldesign v0.3.13
 * (c) 2023 ldesign
 * @license MIT
 */

import { _ as _slicedToArray } from '../_chunks/dep-84acf3c2.mjs';
import { _ as _defineProperty } from '../_chunks/dep-2db7b3ec.mjs';
import { defineComponent, ref, computed, toRefs, watch, onMounted, createVNode, Teleport, mergeProps } from 'vue';
import { addClass, removeClass } from '../utils/dom.mjs';
import { renderTNodeJSX, renderContent } from '../utils/render-tnode.mjs';
import { usePrefixClass, useCommonClassName } from '../hooks/useConfig.mjs';
import useTeleport from '../hooks/useTeleport.mjs';
import props from './props.mjs';
import GradientIcon from './icon/gradient.mjs';
import '../_chunks/dep-b8d7992c.mjs';
import '../_chunks/dep-255303ba.mjs';
import '../_chunks/dep-eba0ea6e.mjs';
import '../_chunks/dep-876fb3ec.mjs';
import '../_chunks/dep-469b4ae0.mjs';
import '../_chunks/dep-b57180d0.mjs';
import '../_chunks/dep-c8d7b6b4.mjs';
import '../_chunks/dep-3da99438.mjs';
import '../_chunks/dep-5717e263.mjs';
import '../_chunks/dep-a8bcacea.mjs';
import '../utils/easing.mjs';
import '../_chunks/dep-888e80c4.mjs';
import '../_chunks/dep-334a4f6b.mjs';
import '../_chunks/dep-e5eb9f23.mjs';
import '../_chunks/dep-9fe2ef12.mjs';
import '../_chunks/dep-672e7d1a.mjs';
import '../_chunks/dep-4d7a675b.mjs';
import '../_chunks/dep-2e7f59b1.mjs';
import '../_chunks/dep-1434aa15.mjs';
import '../_chunks/dep-9262ee2f.mjs';
import '../_chunks/dep-406cd044.mjs';
import '../_chunks/dep-42cc3015.mjs';
import '../_chunks/dep-2bc37d52.mjs';
import '../_chunks/dep-327559e8.mjs';
import '../_chunks/dep-b2235f26.mjs';
import '../_chunks/dep-8b989474.mjs';
import '../_chunks/dep-1372b2d3.mjs';
import '../_chunks/dep-9a85dac1.mjs';
import '../config-provider/useConfig.mjs';
import '../_chunks/dep-095107f7.mjs';
import '../_chunks/dep-c989dff3.mjs';
import '../_chunks/dep-9cf86cf1.mjs';
import '../_chunks/dep-bc1d737a.mjs';
import '../_chunks/dep-855db8bc.mjs';
import '../_chunks/dep-a87f3e4c.mjs';
import '../_chunks/dep-1e566bb5.mjs';
import '../_chunks/dep-42a19209.mjs';
import '../_chunks/dep-8d3e9aa3.mjs';
import '../_chunks/dep-40d69a9c.mjs';
import '../_chunks/dep-dcc83161.mjs';
import '../_chunks/dep-0fc02184.mjs';
import '../_chunks/dep-f1994936.mjs';
import '../_chunks/dep-345e1be3.mjs';
import '../_common/js/global-config/default-config.mjs';
import '../_common/js/global-config/locale/zh_CN.mjs';
import '../_chunks/dep-9888611c.mjs';
import '../_chunks/dep-697a1365.mjs';
import '../config-provider/type.mjs';
import '../_common/js/loading/circle-adapter.mjs';
import '../_common/js/utils/set-style.mjs';
import '../_common/js/utils/helper.mjs';
import '../_chunks/dep-bf1e33c8.mjs';
import '../_chunks/dep-60fae668.mjs';
import '../_chunks/dep-ed5ebb35.mjs';
import '../_chunks/dep-78847b2e.mjs';
import '../_chunks/dep-3f21269a.mjs';

var useComponentClassName = function useComponentClassName() {
  return {
    name: usePrefixClass("loading"),
    centerClass: usePrefixClass("loading--center"),
    fullscreenClass: usePrefixClass("loading__fullscreen"),
    lockClass: usePrefixClass("loading--lock"),
    overlayClass: usePrefixClass("loading__overlay"),
    relativeClass: usePrefixClass("loading__parent"),
    fullClass: usePrefixClass("loading--full"),
    inheritColorClass: usePrefixClass("loading--inherit-color")
  };
};
var _Loading = defineComponent({
  name: "TLoading",
  inheritAttrs: false,
  props: props,
  setup: function setup(props2, _ref) {
    var slots = _ref.slots;
    var delayShowLoading = ref(false);
    var _useComponentClassNam = useComponentClassName(),
      name = _useComponentClassNam.name,
      centerClass = _useComponentClassNam.centerClass,
      fullscreenClass = _useComponentClassNam.fullscreenClass,
      lockClass = _useComponentClassNam.lockClass,
      overlayClass = _useComponentClassNam.overlayClass,
      relativeClass = _useComponentClassNam.relativeClass,
      fullClass = _useComponentClassNam.fullClass,
      inheritColorClass = _useComponentClassNam.inheritColorClass;
    var classPrefix = usePrefixClass();
    var _useCommonClassName = useCommonClassName(),
      SIZE = _useCommonClassName.SIZE;
    var countDelay = function countDelay() {
      delayShowLoading.value = false;
      var timer = setTimeout(function () {
        delayShowLoading.value = true;
        clearTimeout(timer);
      }, props2.delay);
    };
    var teleportElement = useTeleport(function () {
      return props2.attach;
    });
    var delayCounted = computed(function () {
      return Boolean(!props2.delay || props2.delay && delayShowLoading.value);
    });
    var styles = computed(function () {
      var styles2 = {};
      if (props2.zIndex !== void 0) styles2.zIndex = props2.zIndex;
      if (!["small", "medium", "large"].includes(props2.size)) styles2["font-size"] = props2.size;
      return styles2;
    });
    var hasContent = computed(function () {
      return Boolean(props2["default"] || slots["default"] || props2.content || slots.content);
    });
    var lockFullscreen = computed(function () {
      return props2.preventScrollThrough && props2.fullscreen;
    });
    var showText = computed(function () {
      return Boolean(props2.text || slots.text);
    });
    var showWrapLoading = computed(function () {
      return hasContent.value && props2.loading && delayCounted.value;
    });
    var showFullScreenLoading = computed(function () {
      return props2.fullscreen && props2.loading && delayCounted.value;
    });
    var showNormalLoading = computed(function () {
      return props2.attach && props2.loading && delayCounted.value;
    });
    var showAttachedLoading = computed(function () {
      return props2.attach && props2.loading && delayCounted.value;
    });
    var classes = computed(function () {
      var baseClasses = [centerClass.value, SIZE.value[props2.size], _defineProperty({}, inheritColorClass.value, props2.inheritColor)];
      var fullScreenClasses = [name.value, fullscreenClass.value, centerClass.value, overlayClass.value];
      return {
        baseClasses: baseClasses,
        attachClasses: baseClasses.concat([name.value, fullClass.value, _defineProperty({}, overlayClass.value, props2.showOverlay)]),
        withContentClasses: baseClasses.concat([name.value, fullClass.value, _defineProperty({}, overlayClass.value, props2.showOverlay)]),
        fullScreenClasses: fullScreenClasses,
        normalClasses: baseClasses.concat([name.value])
      };
    });
    var _toRefs = toRefs(props2),
      loading = _toRefs.loading;
    watch([loading], function (_ref5) {
      var _ref6 = _slicedToArray(_ref5, 1),
        isLoading = _ref6[0];
      if (isLoading) {
        countDelay();
        lockFullscreen.value && addClass(document.body, lockClass.value);
      } else {
        lockFullscreen.value && removeClass(document.body, lockClass.value);
      }
    });
    onMounted(function () {
      props2.delay && countDelay();
    });
    return {
      classPrefix: classPrefix,
      relativeClass: relativeClass,
      delayShowLoading: delayShowLoading,
      styles: styles,
      showText: showText,
      hasContent: hasContent,
      classes: classes,
      lockFullscreen: lockFullscreen,
      showWrapLoading: showWrapLoading,
      showNormalLoading: showNormalLoading,
      showFullScreenLoading: showFullScreenLoading,
      showAttachedLoading: showAttachedLoading,
      teleportElement: teleportElement
    };
  },
  render: function render() {
    var _this = this;
    var _this$classes = this.classes,
      fullScreenClasses = _this$classes.fullScreenClasses,
      baseClasses = _this$classes.baseClasses,
      withContentClasses = _this$classes.withContentClasses,
      attachClasses = _this$classes.attachClasses,
      normalClasses = _this$classes.normalClasses;
    var defaultIndicator = createVNode(GradientIcon, {
      "size": this.size
    }, null);
    var indicator = this.loading && renderTNodeJSX(this, "indicator", defaultIndicator);
    var text = this.showText && createVNode("div", {
      "class": "".concat(this.classPrefix, "-loading__text")
    }, [renderTNodeJSX(this, "text")]);
    if (this.fullscreen) {
      if (!this.showFullScreenLoading || !this.loading) return null;
      return createVNode(Teleport, {
        "disabled": !this.attach || !this.teleportElement,
        "to": this.teleportElement
      }, {
        "default": function _default() {
          return [createVNode("div", mergeProps({
            "class": fullScreenClasses,
            "style": _this.styles
          }, _this.$attrs), [createVNode("div", {
            "class": baseClasses
          }, [indicator, text])])];
        }
      });
    }
    if (this.hasContent) {
      return createVNode("div", mergeProps({
        "class": this.relativeClass
      }, this.$attrs), [renderContent(this, "default", "content"), this.showWrapLoading && createVNode("div", {
        "class": withContentClasses,
        "style": this.styles
      }, [indicator, text])]);
    }
    if (this.attach) {
      if (!this.showAttachedLoading || !this.loading) return null;
      return createVNode(Teleport, {
        "disabled": !this.attach || !this.teleportElement,
        "to": this.teleportElement
      }, {
        "default": function _default() {
          return [createVNode("div", mergeProps({
            "class": attachClasses,
            "style": _this.styles
          }, _this.$attrs), [indicator, text])];
        }
      });
    }
    return this.loading ? createVNode("div", mergeProps({
      "class": normalClasses,
      "style": this.styles
    }, this.$attrs), [indicator, text]) : null;
  }
});

export { _Loading as default };
//# sourceMappingURL=loading.mjs.map
