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

import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { defineComponent, ref, computed, toRefs, watch, onMounted, createVNode, Teleport, mergeProps } from 'vue';
import { addClass, removeClass } from '../utils/dom.js';
import { renderTNodeJSX, renderContent } from '../utils/render-tnode.js';
import { usePrefixClass, useCommonClassName } from '../hooks/useConfig.js';
import useTeleport from '../hooks/useTeleport.js';
import props from './props.js';
import GradientIcon from './icon/gradient.js';
import '../_chunks/dep-e041f5b0.js';
import 'lodash/isString';
import 'lodash/isFunction';
import 'lodash/isArray';
import '../utils/easing.js';
import 'lodash/isEmpty';
import 'lodash/isObject';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import '../config-provider/useConfig.js';
import 'lodash/cloneDeep';
import '../config-provider/context.js';
import 'lodash/mergeWith';
import 'lodash/merge';
import '../_common/js/global-config/default-config.js';
import '../_common/js/global-config/locale/zh_CN.js';
import '@babel/runtime/helpers/typeof';
import 'dayjs';
import '../_common/js/loading/circle-adapter.js';
import '../_common/js/utils/set-style.js';
import '../_common/js/utils/helper.js';
import '@babel/runtime/helpers/toConsumableArray';
import '@babel/runtime/helpers/objectWithoutProperties';
import 'lodash/isNull';
import 'lodash/isUndefined';
import 'lodash/isNumber';

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.js.map
