/**
 * ldesign v0.4.6
 * (c) 2023 ldesign
 * @license MIT
 */

import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { addClass, removeClass } from '../utils/dom.js';
import { renderTNodeJSX, renderContent } from '../utils/render-tnode.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 '../utils/easing.js';
import '@babel/runtime/helpers/typeof';
import '@vue/composition-api';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import 'lodash/mergeWith';
import '../config-provider/context.js';
import 'lodash/merge';
import '../_common/js/global-config/default-config.js';
import '../_common/js/global-config/locale/zh_CN.js';
import '../_chunks/dep-be599ec8.js';
import 'dayjs';
import '../_chunks/dep-67ff4010.js';
import '../config-provider/type.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/toConsumableArray';
import '@babel/runtime/helpers/objectWithoutProperties';
import '@babel/runtime/helpers/slicedToArray';
import 'lodash/isNull';
import 'lodash/isUndefined';
import 'lodash/isNumber';
import 'lodash/isArray';

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 classPrefixMixins = getClassPrefixMixins("loading");
var _Loading = mixins(classPrefixMixins).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, "".concat(this.componentName, "--lock"));
        } else {
          this.lockFullscreen && 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({}, "".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({}, "".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({}, "".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(GradientIcon, {
      "attrs": {
        "size": this.size
      }
    });
    var indicator = this.loading && renderTNodeJSX(this, "indicator", defaultIndicator);
    var text = this.showText && h("div", {
      "class": "".concat(this.classPrefix, "-loading__text")
    }, [renderTNodeJSX(this, "text")]);
    if (this.fullscreen) {
      if (!this.showFullScreenLoading || !this.loading) 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")
      }, [renderContent(this, "default", "content"), this.showWrapLoading && h("div", {
        "class": this.withContentClasses,
        "style": this.styles
      }, [indicator, text])]);
    }
    if (this.attach) {
      if (!this.showAttachedLoading || !this.loading) return;
      return h("div", {
        "class": this.attachClasses,
        "style": this.styles,
        "directives": [{
          name: "transfer-dom",
          value: this.attach
        }]
      }, [indicator, text]);
    }
    if (this.loading) {
      return h("div", {
        "class": this.normalClasses,
        "style": this.styles
      }, [indicator, text]);
    }
    return null;
  }
});

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