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

import { addClass, removeClass } from '../../utils/dom.js';
import { renderLNodeJSX, renderContent } from '../../utils/render-node.js';
import TransferDom from '../../utils/transfer-dom.js';
import { getClassPrefixMixins } from '../config-provider/config-receiver.js';
import mixins from '../../utils/mixins.js';
import props from './props.js';
import GradientIcon from './icon/gradient.js';
import 'vue';
import 'raf';
import 'lodash/isString';
import '../../chunks/index.js';
import '../../chunks/log.js';
import '../../chunks/_commonjsHelpers-2e6815bd.js';
import '../../utils/easing.js';
import 'lodash';
import 'lodash/mergeWith';
import '../config-provider/context.js';
import '../../chunks/zh_CN.js';
import '../config-provider/type.js';
import '../../chunks/defineProperty-838e4192.js';
import '../../chunks/set-style.js';
import '../../chunks/helper2.js';
import '../../config.js';

const classPrefixMixins = getClassPrefixMixins("loading");
var _Loading = mixins(classPrefixMixins).extend({
  name: "LLoading",
  props: {
    ...props
  },
  components: {
    GradientIcon
  },
  directives: {
    TransferDom
  },
  data() {
    return {
      delayShowLoading: false
    };
  },
  created() {
    this.delay && this.countDelay();
  },
  watch: {
    loading: {
      handler(value) {
        if (value) {
          this.countDelay();
          this.lockFullscreen && addClass(document.body, `${this.componentName}--lock`);
        } else {
          this.lockFullscreen && 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 && renderLNodeJSX(this, "indicator", defaultIndicator);
    const text = this.showText && h("div", {
      "class": `${this.classPrefix}-loading__text`
    }, [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`
      }, [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
