/**
 * ldesign v0.2.2
 * (c) 2022年9月20日 swimly
 * @license MIT
 */

'use strict';

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

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var components_loading_icon_gradient = require('./icon/gradient.js');
var utils_dom = require('../../utils/dom.js');
var utils_renderNode = require('../../utils/render-node.js');
var utils_transferDom = require('../../utils/transfer-dom.js');
var components_loading_props = require('./props.js');
var components_configProvider_configReceiver = require('../config-provider/config-receiver.js');
var utils_mixins = require('../../utils/mixins.js');
require('vue');
require('../../chunks/defineProperty-28395935.js');
require('../../chunks/set-style.js');
require('../../chunks/helper2.js');
require('@babel/runtime/helpers/toConsumableArray');
require('@babel/runtime/helpers/slicedToArray');
require('../../config.js');
require('raf');
require('lodash/isString');
require('../../utils/easing.js');
require('@babel/runtime/helpers/typeof');
require('lodash/camelCase');
require('lodash/kebabCase');
require('lodash/mergeWith');
require('lodash');
require('../config-provider/context.js');
require('../../chunks/zh_CN.js');

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

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

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 classPrefixMixins = components_configProvider_configReceiver.getClassPrefixMixins("loading");
var _Loading = utils_mixins["default"](classPrefixMixins).extend({
  name: "LLoading",
  props: _objectSpread({}, components_loading_props["default"]),
  components: {
    GradientIcon: components_loading_icon_gradient["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, "".concat(this.componentName, "--lock"));
        } else {
          this.lockFullscreen && utils_dom.removeClass(document.body, "".concat(this.componentName, "--lock"));
        }
      },
      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 ["".concat(this.componentName, "--center"), this.commonSizeClassName[this.size], _defineProperty__default["default"]({}, "".concat(this.componentName, "--inherit-color"), this.inheritColor)];
    },
    hasContent: function hasContent() {
      return Boolean(this["default"] || this.$scopedSlots["default"] || this.content || this.$scopedSlots.content);
    },
    withContentClasses: function withContentClasses() {
      return this.baseClasses.concat([this.componentName, "".concat(this.componentName, "--full"), _defineProperty__default["default"]({}, "".concat(this.componentName, "__overlay"), this.showOverlay)]);
    },
    fullScreenClasses: function fullScreenClasses() {
      return [this.componentName, "".concat(this.componentName, "__fullscreen"), "".concat(this.componentName, "--center"), "".concat(this.componentName, "__overlay")];
    },
    attachClasses: function attachClasses() {
      return this.baseClasses.concat([this.componentName, "".concat(this.componentName, "--full"), _defineProperty__default["default"]({}, "".concat(this.componentName, "__overlay"), this.showOverlay)]);
    },
    normalClasses: function normalClasses() {
      return this.baseClasses.concat([this.componentName]);
    },
    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("gradient-icon", {
      "attrs": {
        "size": this.size
      }
    });
    var indicator = this.loading && utils_renderNode.renderLNodeJSX(this, "indicator", defaultIndicator);
    var text = this.showText && h("div", {
      "class": "".concat(this.classPrefix, "-loading__text")
    }, [utils_renderNode.renderLNodeJSX(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": "".concat(this.componentName, "__parent")
      }, [utils_renderNode.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
