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

import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { defineComponent, reactive, h, createApp } from 'vue';
import { getAttach, addClass, removeClass } from '../utils/dom.js';
import { usePrefixClass } from '../hooks/useConfig.js';
import _Loading from './loading.js';
import '../_chunks/dep-2e5d8948.js';
import 'lodash/isString';
import 'lodash/isFunction';
import 'lodash/isArray';
import '../utils/easing.js';
import '../config-provider/useConfig.js';
import 'lodash/cloneDeep';
import '../config-provider/context.js';
import 'lodash/mergeWith';
import 'lodash/merge';
import '../_common/js/global-config/default-config.js';
import '../_common/js/global-config/locale/zh_CN.js';
import '@babel/runtime/helpers/typeof';
import 'dayjs';
import '../_chunks/dep-4580aabe.js';
import '../config-provider/type.js';
import '@babel/runtime/helpers/slicedToArray';
import '../utils/render-tnode.js';
import 'lodash/isEmpty';
import 'lodash/isObject';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import '../hooks/useTeleport.js';
import './props.js';
import './icon/gradient.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 'lodash/isNull';
import 'lodash/isUndefined';
import 'lodash/isNumber';

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 fullScreenLoadingInstance = null;
function createLoading(props) {
  var component = defineComponent({
    setup: function setup() {
      var loadingOptions = reactive(props);
      return {
        loadingOptions: loadingOptions
      };
    },
    render: function render() {
      return h(_Loading, _objectSpread({}, this.loadingOptions));
    }
  });
  var attach = getAttach(props.attach);
  var loading = createApp(component).mount(document.createElement("div"));
  var parentRelativeClass = usePrefixClass("loading__parent--relative").value;
  var prefixClass = usePrefixClass("loading");
  if (attach) addClass(attach, parentRelativeClass);else console.error("attach is not exist");
  var loadingInstance = {
    hide: function hide() {
      var _attach$querySelector;
      loading.loading = false;
      (_attach$querySelector = attach.querySelectorAll(".".concat(prefixClass.value))) === null || _attach$querySelector === void 0 ? void 0 : _attach$querySelector.forEach(function (item) {
        item.remove();
      });
      removeClass(attach, parentRelativeClass);
    }
  };
  return loadingInstance;
}
function produceLoading(props) {
  var lockClass = usePrefixClass("loading--lock");
  if (props === true) {
    fullScreenLoadingInstance = createLoading({
      fullscreen: true,
      loading: true,
      attach: "body"
    });
    return fullScreenLoadingInstance;
  }
  removeClass(document.body, lockClass.value);
  if (props === false) {
    removeClass(document.body, lockClass.value);
    fullScreenLoadingInstance.hide();
    fullScreenLoadingInstance = null;
    return;
  }
  return createLoading(props);
}
var LoadingPlugin = produceLoading;
LoadingPlugin.install = function (app) {
  app.config.globalProperties.$loading = produceLoading;
};

export { LoadingPlugin as default };
//# sourceMappingURL=plugin.js.map
