/**
 * ldesign v0.2.14
 * (c) 2022/11/2 16:16 built by swimly
 * @license MIT
 */

'use strict';

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

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_configProvider_configReceiver = require('../config-provider/config-receiver.js');
var utils_mixins = require('../../utils/mixins.js');
var components_loading_props = require('./props.js');
var components_loading_icon_gradient = require('./icon/gradient.js');
require('vue');
require('raf');
require('lodash/isString');
require('../../chunks/log.js');
require('../../chunks/_commonjsHelpers-2e6815bd.js');
require('../../utils/easing.js');
require('lodash');
require('lodash/mergeWith');
require('../config-provider/context.js');
require('../../chunks/zh_CN.js');
require('../../chunks/defineProperty-838e4192.js');
require('../../chunks/set-style.js');
require('../../chunks/helper2.js');
require('../../config.js');

const classPrefixMixins = components_configProvider_configReceiver.getClassPrefixMixins("loading");
var _Loading = utils_mixins["default"](classPrefixMixins).extend({
  name: "LLoading",
  props: {
    ...components_loading_props["default"]
  },
  components: {
    GradientIcon: components_loading_icon_gradient["default"]
  },
  directives: {
    TransferDom: utils_transferDom["default"]
  },
  data() {
    return {
      delayShowLoading: false
    };
  },
  created() {
    this.delay && this.countDelay();
  },
  watch: {
    loading: {
      handler(value) {
        if (value) {
          this.countDelay();
          this.lockFullscreen && utils_dom.addClass(document.body, `${this.componentName}--lock`);
        } else {
          this.lockFullscreen && utils_dom.removeClass(document.body, `${this.componentName}--lock`);
        }
      },
      immediate: true
    }
  },
  computed: {
    styles() {
      const 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() {
      return Boolean(this.text || this.$scopedSlots.text);
    },
    baseClasses() {
      return [`${this.componentName}--center`, this.commonSizeClassName[this.size], {
        [`${this.componentName}--inherit-color`]: this.inheritColor
      }];
    },
    hasContent() {
      return Boolean(this.default || this.$scopedSlots.default || this.content || this.$scopedSlots.content);
    },
    withContentClasses() {
      return this.baseClasses.concat([this.componentName, `${this.componentName}--full`, {
        [`${this.componentName}__overlay`]: this.showOverlay
      }]);
    },
    fullScreenClasses() {
      return [this.componentName, `${this.componentName}__fullscreen`, `${this.componentName}--center`, `${this.componentName}__overlay`];
    },
    attachClasses() {
      return this.baseClasses.concat([this.componentName, `${this.componentName}--full`, {
        [`${this.componentName}__overlay`]: this.showOverlay
      }]);
    },
    normalClasses() {
      return this.baseClasses.concat([this.componentName]);
    },
    lockFullscreen() {
      return this.preventScrollThrough && this.fullscreen;
    },
    delayCounted() {
      return Boolean(!this.delay || this.delay && this.delayShowLoading);
    },
    showWrapLoading() {
      return this.hasContent && this.loading && this.delayCounted;
    },
    showFullScreenLoading() {
      return this.fullscreen && this.loading && this.delayCounted;
    },
    showAttachedLoading() {
      return this.attach && this.loading && this.delayCounted;
    }
  },
  methods: {
    countDelay() {
      this.delayShowLoading = false;
      const timer = setTimeout(() => {
        this.delayShowLoading = true;
        clearTimeout(timer);
      }, this.delay);
    }
  },
  render() {
    const h = arguments[0];
    const defaultIndicator = h("gradient-icon", {
      "attrs": {
        "size": this.size
      }
    });
    const indicator = this.loading && utils_renderNode.renderLNodeJSX(this, "indicator", defaultIndicator);
    const text = this.showText && h("div", {
      "class": `${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": `${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
