/**
 * tdesign v0.39.1-alpha.1
 * (c) 2022 tdesign
 * @license MIT
 */

'use strict';

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

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var Vue = require('vue');
var loading_icon_gradient = require('./icon/gradient.js');
var config = require('../config.js');
var utils_classnames = require('../utils/classnames.js');
var utils_dom = require('../utils/dom.js');
var utils_renderTnode = require('../utils/render-tnode.js');
var utils_transferDom = require('../utils/transfer-dom.js');
var loading_props = require('./props.js');
require('../_common/js/loading/circle-adapter.js');
require('../_common/js/utils/set-style.js');
require('../_common/js/utils/helper.js');
require('@babel/runtime/helpers/objectWithoutProperties');
require('@babel/runtime/helpers/slicedToArray');
require('raf');
require('lodash/isString');
require('../utils/easing.js');
require('@babel/runtime/helpers/typeof');
require('lodash/isObject');

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

var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
var Vue__default = /*#__PURE__*/_interopDefaultLegacy(Vue);

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__default["default"](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(config.prefix, "-loading");
var centerClass = "".concat(config.prefix, "-loading--center");
var fullscreenClass = "".concat(config.prefix, "-loading__fullscreen");
var lockClass = "".concat(config.prefix, "-loading--lock");
var overlayClass = "".concat(config.prefix, "-loading__overlay");
var relativeClass = "".concat(config.prefix, "-loading__parent");
var fullClass = "".concat(config.prefix, "-loading--full");
var inheritColorClass = "".concat(config.prefix, "-loading--inherit-color");
var _Loading = Vue__default["default"].extend({
  name: "TLoading",
  props: _objectSpread({}, loading_props["default"]),
  directives: {
    TransferDom: utils_transferDom["default"]
  },
  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 && utils_dom.addClass(document.body, lockClass);
        } else {
          this.lockFullscreen && utils_dom.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, utils_classnames.SIZE_CLASSNAMES[this.size], _defineProperty__default["default"]({}, 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__default["default"]({}, overlayClass, this.showOverlay)]);
    },
    fullScreenClasses: function fullScreenClasses() {
      return [name, fullscreenClass, centerClass, overlayClass];
    },
    attachClasses: function attachClasses() {
      return this.baseClasses.concat([name, fullClass, _defineProperty__default["default"]({}, 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(loading_icon_gradient["default"], {
      "attrs": {
        "size": this.size
      }
    });
    var indicator = this.loading && utils_renderTnode.renderTNodeJSX(this, "indicator", defaultIndicator);
    var text = this.showText && h("div", {
      "class": "".concat(config.prefix, "-loading__text")
    }, [utils_renderTnode.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
      }, [utils_renderTnode.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]);
  }
});

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