"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const vue = require("vue");
const comp = require("../../ui/src/comp.js");
require("../../ui/index.js");
const vn = require("../../ui/src/vn.js");
const XEUtils = require("xe-utils");
const i18n = require("../../../../@vxe-ui/core/es/src/i18n.js");
const config = require("../../../../@vxe-ui/core/es/src/config.js");
const useFns = require("../../../../@vxe-ui/core/es/src/useFns.js");
const icon = require("../../../../@vxe-ui/core/es/src/icon.js");
const event = require("../../../../@vxe-ui/core/es/src/event.js");
const index_esm = require("../../../../@vxe-ui/core/es/index.esm.js");
const VxeLoadingComponent = comp.defineVxeComponent({
  name: "VxeLoading",
  props: {
    modelValue: Boolean,
    icon: {
      type: String,
      default: () => config.getConfig().loading.icon
    },
    showIcon: {
      type: Boolean,
      default: () => config.getConfig().loading.showIcon
    },
    text: {
      type: String,
      default: () => config.getConfig().loading.text
    },
    showText: {
      type: Boolean,
      default: () => config.getConfig().loading.showText
    },
    status: String,
    size: {
      type: String,
      default: () => config.getConfig().loading.size || config.getConfig().size
    }
  },
  setup(props, context) {
    const { slots, emit } = context;
    const xID = XEUtils.uniqueId();
    const { computeSize } = useFns.useSize(props);
    const reactData = vue.reactive({
      initialized: false
    });
    const computeMaps = {
      computeSize
    };
    const $xeLoading = {
      xID,
      props,
      context,
      reactData,
      getComputeMaps: () => computeMaps
    };
    const computeLoadingIcon = vue.computed(() => {
      return props.icon || icon.getIcon().LOADING;
    });
    const computeLoadingText = vue.computed(() => {
      const { text } = props;
      return XEUtils.isString(text) ? text : i18n.getI18n("vxe.loading.text");
    });
    const handleInit = () => {
      if (!reactData.initialized) {
        reactData.initialized = !!reactData.initialized;
      }
    };
    const dispatchEvent = (type, params, evnt) => {
      emit(type, event.createEvent(evnt, { $loading: $xeLoading }, params));
    };
    const loadingMethods = {
      dispatchEvent
    };
    const loadingPrivateMethods = {};
    Object.assign($xeLoading, loadingMethods, loadingPrivateMethods);
    const renderVN = () => {
      const { modelValue, showIcon, status } = props;
      const { initialized } = reactData;
      const vSize = computeSize.value;
      const defaultSlot = slots.default;
      const textSlot = slots.text;
      const iconSlot = slots.icon;
      const loadingIcon = computeLoadingIcon.value;
      const loadingText = computeLoadingText.value;
      if (!initialized && !modelValue) {
        return index_esm.renderEmptyElement();
      }
      return vue.h("div", {
        class: ["vxe-loading", {
          [`size--${vSize}`]: vSize,
          [`theme--${status}`]: status,
          "is--visible": modelValue
        }]
      }, defaultSlot ? [
        vue.h("div", {
          class: "vxe-loading--wrapper"
        }, vn.getSlotVNs(defaultSlot({})))
      ] : [
        vue.h("div", {
          class: "vxe-loading--chunk"
        }, [
          showIcon && (iconSlot || loadingIcon) ? vue.h("div", {
            class: "vxe-loading--icon"
          }, iconSlot ? vn.getSlotVNs(iconSlot({})) : [
            vue.h("i", {
              class: loadingIcon
            })
          ]) : vue.h("div", {
            class: "vxe-loading--spinner"
          }),
          textSlot || loadingText ? vue.h("div", {
            class: "vxe-loading--text"
          }, textSlot ? vn.getSlotVNs(textSlot({})) : `${loadingText}`) : null
        ])
      ]);
    };
    vue.watch(() => props.modelValue, () => {
      handleInit();
    });
    handleInit();
    $xeLoading.renderVN = renderVN;
    return $xeLoading;
  },
  render() {
    return this.renderVN();
  }
});
exports.default = VxeLoadingComponent;
