/**
 * tdesign v0.41.7
 * (c) 2022 tdesign
 * @license MIT
 */

import _defineProperty from '@babel/runtime/helpers/defineProperty';
import Vue from 'vue';
import GradientIcon from './icon/gradient.js';
import { prefix } from '../config.js';
import { SIZE_CLASSNAMES } from '../utils/classnames.js';
import { addClass, removeClass } from '../utils/dom.js';
import { renderTNodeJSX, renderContent } from '../utils/render-tnode.js';
import TransferDom from '../utils/transfer-dom.js';
import props from './props.js';
import '../_common/js/loading/circle-adapter.js';
import '../_common/js/utils/set-style.js';
import '../_common/js/utils/helper.js';
import '@babel/runtime/helpers/objectWithoutProperties';
import '@babel/runtime/helpers/slicedToArray';
import 'raf';
import 'lodash/isString';
import '../utils/easing.js';
import '@babel/runtime/helpers/typeof';

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
var name = "".concat(prefix, "-loading");
var centerClass = "".concat(prefix, "-loading--center");
var fullscreenClass = "".concat(prefix, "-loading__fullscreen");
var lockClass = "".concat(prefix, "-loading--lock");
var overlayClass = "".concat(prefix, "-loading__overlay");
var relativeClass = "".concat(prefix, "-loading__parent");
var fullClass = "".concat(prefix, "-loading--full");
var inheritColorClass = "".concat(prefix, "-loading--inherit-color");
var _Loading = Vue.extend({
  name: "TLoading",
  props: _objectSpread({}, props),
  directives: {
    TransferDom: TransferDom
  },
  data: function data() {
    return {
      delayShowLoading: false
    };
  },
  created: function created() {
    this.delay && this.countDelay();
  },
  watch: {
    loading: {
      handler: function handler(value) {
        if (value) {
          this.countDelay();
          this.lockFullscreen && addClass(document.body, lockClass);
        } else {
          this.lockFullscreen && removeClass(document.body, lockClass);
        }
      },
      immediate: true
    }
  },
  computed: {
    styles: function styles() {
      var styles = {};

      if (this.zIndex !== void 0) {
        styles.zIndex = this.zIndex;
      }

      if (!["small", "medium", "large"].includes(this.size)) {
        styles["font-size"] = this.size;
      }

      return styles;
    },
    showText: function showText() {
      return Boolean(this.text || this.$scopedSlots.text);
    },
    baseClasses: function baseClasses() {
      return [centerClass, SIZE_CLASSNAMES[this.size], _defineProperty({}, inheritColorClass, this.inheritColor)];
    },
    hasContent: function hasContent() {
      return Boolean(this["default"] || this.$scopedSlots["default"] || this.content || this.$scopedSlots.content);
    },
    withContentClasses: function withContentClasses() {
      return this.baseClasses.concat([name, fullClass, _defineProperty({}, overlayClass, this.showOverlay)]);
    },
    fullScreenClasses: function fullScreenClasses() {
      return [name, fullscreenClass, centerClass, overlayClass];
    },
    attachClasses: function attachClasses() {
      return this.baseClasses.concat([name, fullClass, _defineProperty({}, overlayClass, this.showOverlay)]);
    },
    normalClasses: function normalClasses() {
      return this.baseClasses.concat([name]);
    },
    lockFullscreen: function lockFullscreen() {
      return this.preventScrollThrough && this.fullscreen;
    },
    delayCounted: function delayCounted() {
      return Boolean(!this.delay || this.delay && this.delayShowLoading);
    },
    showWrapLoading: function showWrapLoading() {
      return this.hasContent && this.loading && this.delayCounted;
    },
    showFullScreenLoading: function showFullScreenLoading() {
      return this.fullscreen && this.loading && this.delayCounted;
    },
    showAttachedLoading: function showAttachedLoading() {
      return this.attach && this.loading && this.delayCounted;
    }
  },
  methods: {
    countDelay: function countDelay() {
      var _this = this;

      this.delayShowLoading = false;
      var timer = setTimeout(function () {
        _this.delayShowLoading = true;
        clearTimeout(timer);
      }, this.delay);
    }
  },
  render: function render() {
    var h = arguments[0];
    var defaultIndicator = h(GradientIcon, {
      "attrs": {
        "size": this.size
      }
    });
    var indicator = this.loading && renderTNodeJSX(this, "indicator", defaultIndicator);
    var text = this.showText && h("div", {
      "class": "".concat(prefix, "-loading__text")
    }, [renderTNodeJSX(this, "text")]);

    if (this.fullscreen) {
      if (!this.showFullScreenLoading) return null;
      return h("div", {
        "class": this.fullScreenClasses,
        "style": this.styles,
        "directives": [{
          name: "transfer-dom",
          value: this.attach
        }]
      }, [h("div", {
        "class": this.baseClasses
      }, [indicator, text])]);
    }

    if (this.hasContent) {
      return h("div", {
        "class": relativeClass
      }, [renderContent(this, "default", "content"), this.showWrapLoading && h("div", {
        "class": this.withContentClasses,
        "style": this.styles
      }, [indicator, text])]);
    }

    if (this.attach) {
      if (!this.showAttachedLoading) return;
      return h("div", {
        "class": this.attachClasses,
        "style": this.styles,
        "directives": [{
          name: "transfer-dom",
          value: this.attach
        }]
      }, [indicator, text]);
    }

    return h("div", {
      "class": this.normalClasses,
      "style": this.styles
    }, [indicator, text]);
  }
});

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