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

'use strict';

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

var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var vue = require('vue');
var utils_dom = require('../utils/dom.js');
var utils_renderTnode = require('../utils/render-tnode.js');
var hooks_useConfig = require('../hooks/useConfig.js');
var hooks_useTeleport = require('../hooks/useTeleport.js');
var loading_props = require('./props.js');
var loading_icon_gradient = require('./icon/gradient.js');
require('../_chunks/dep-f4db2590.js');
require('lodash/isString');
require('lodash/isFunction');
require('lodash/isArray');
require('../utils/easing.js');
require('lodash/isEmpty');
require('lodash/isObject');
require('lodash/camelCase');
require('lodash/kebabCase');
require('../config-provider/useConfig.js');
require('lodash/cloneDeep');
require('../config-provider/context.js');
require('lodash/mergeWith');
require('lodash/merge');
require('../_common/js/global-config/default-config.js');
require('../_common/js/global-config/locale/zh_CN.js');
require('@babel/runtime/helpers/typeof');
require('dayjs');
require('../_common/js/loading/circle-adapter.js');
require('../_common/js/utils/set-style.js');
require('../_common/js/utils/helper.js');
require('@babel/runtime/helpers/toConsumableArray');
require('@babel/runtime/helpers/objectWithoutProperties');
require('lodash/isNull');
require('lodash/isUndefined');
require('lodash/isNumber');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var _slicedToArray__default = /*#__PURE__*/_interopDefaultLegacy(_slicedToArray);
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);

var useComponentClassName = function useComponentClassName() {
  return {
    name: hooks_useConfig.usePrefixClass("loading"),
    centerClass: hooks_useConfig.usePrefixClass("loading--center"),
    fullscreenClass: hooks_useConfig.usePrefixClass("loading__fullscreen"),
    lockClass: hooks_useConfig.usePrefixClass("loading--lock"),
    overlayClass: hooks_useConfig.usePrefixClass("loading__overlay"),
    relativeClass: hooks_useConfig.usePrefixClass("loading__parent"),
    fullClass: hooks_useConfig.usePrefixClass("loading--full"),
    inheritColorClass: hooks_useConfig.usePrefixClass("loading--inherit-color")
  };
};
var _Loading = vue.defineComponent({
  name: "TLoading",
  inheritAttrs: false,
  props: loading_props["default"],
  setup: function setup(props2, _ref) {
    var slots = _ref.slots;
    var delayShowLoading = vue.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 = hooks_useConfig.usePrefixClass();
    var _useCommonClassName = hooks_useConfig.useCommonClassName(),
      SIZE = _useCommonClassName.SIZE;
    var countDelay = function countDelay() {
      delayShowLoading.value = false;
      var timer = setTimeout(function () {
        delayShowLoading.value = true;
        clearTimeout(timer);
      }, props2.delay);
    };
    var teleportElement = hooks_useTeleport["default"](function () {
      return props2.attach;
    });
    var delayCounted = vue.computed(function () {
      return Boolean(!props2.delay || props2.delay && delayShowLoading.value);
    });
    var styles = vue.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 = vue.computed(function () {
      return Boolean(props2["default"] || slots["default"] || props2.content || slots.content);
    });
    var lockFullscreen = vue.computed(function () {
      return props2.preventScrollThrough && props2.fullscreen;
    });
    var showText = vue.computed(function () {
      return Boolean(props2.text || slots.text);
    });
    var showWrapLoading = vue.computed(function () {
      return hasContent.value && props2.loading && delayCounted.value;
    });
    var showFullScreenLoading = vue.computed(function () {
      return props2.fullscreen && props2.loading && delayCounted.value;
    });
    var showNormalLoading = vue.computed(function () {
      return props2.attach && props2.loading && delayCounted.value;
    });
    var showAttachedLoading = vue.computed(function () {
      return props2.attach && props2.loading && delayCounted.value;
    });
    var classes = vue.computed(function () {
      var baseClasses = [centerClass.value, SIZE.value[props2.size], _defineProperty__default["default"]({}, 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__default["default"]({}, overlayClass.value, props2.showOverlay)]),
        withContentClasses: baseClasses.concat([name.value, fullClass.value, _defineProperty__default["default"]({}, overlayClass.value, props2.showOverlay)]),
        fullScreenClasses: fullScreenClasses,
        normalClasses: baseClasses.concat([name.value])
      };
    });
    var _toRefs = vue.toRefs(props2),
      loading = _toRefs.loading;
    vue.watch([loading], function (_ref5) {
      var _ref6 = _slicedToArray__default["default"](_ref5, 1),
        isLoading = _ref6[0];
      if (isLoading) {
        countDelay();
        lockFullscreen.value && utils_dom.addClass(document.body, lockClass.value);
      } else {
        lockFullscreen.value && utils_dom.removeClass(document.body, lockClass.value);
      }
    });
    vue.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 = vue.createVNode(loading_icon_gradient["default"], {
      "size": this.size
    }, null);
    var indicator = this.loading && utils_renderTnode.renderTNodeJSX(this, "indicator", defaultIndicator);
    var text = this.showText && vue.createVNode("div", {
      "class": "".concat(this.classPrefix, "-loading__text")
    }, [utils_renderTnode.renderTNodeJSX(this, "text")]);
    if (this.fullscreen) {
      if (!this.showFullScreenLoading || !this.loading) return null;
      return vue.createVNode(vue.Teleport, {
        "disabled": !this.attach || !this.teleportElement,
        "to": this.teleportElement
      }, {
        "default": function _default() {
          return [vue.createVNode("div", vue.mergeProps({
            "class": fullScreenClasses,
            "style": _this.styles
          }, _this.$attrs), [vue.createVNode("div", {
            "class": baseClasses
          }, [indicator, text])])];
        }
      });
    }
    if (this.hasContent) {
      return vue.createVNode("div", vue.mergeProps({
        "class": this.relativeClass
      }, this.$attrs), [utils_renderTnode.renderContent(this, "default", "content"), this.showWrapLoading && vue.createVNode("div", {
        "class": withContentClasses,
        "style": this.styles
      }, [indicator, text])]);
    }
    if (this.attach) {
      if (!this.showAttachedLoading || !this.loading) return null;
      return vue.createVNode(vue.Teleport, {
        "disabled": !this.attach || !this.teleportElement,
        "to": this.teleportElement
      }, {
        "default": function _default() {
          return [vue.createVNode("div", vue.mergeProps({
            "class": attachClasses,
            "style": _this.styles
          }, _this.$attrs), [indicator, text])];
        }
      });
    }
    return this.loading ? vue.createVNode("div", vue.mergeProps({
      "class": normalClasses,
      "style": this.styles
    }, this.$attrs), [indicator, text]) : null;
  }
});

exports["default"] = _Loading;
//# sourceMappingURL=loading.js.map
