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

'use strict';

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

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var vue = require('vue');
var utils_dom = require('../utils/dom.js');
var hooks_useConfig = require('../hooks/useConfig.js');
var loading_loading = require('./loading.js');
require('../_chunks/dep-7f0559c3.js');
require('lodash/isString');
require('lodash/isFunction');
require('lodash/isArray');
require('../utils/easing.js');
require('../config-provider/useConfig.js');
require('lodash/cloneDeep');
require('../config-provider/context.js');
require('lodash/mergeWith');
require('lodash/merge');
require('../_common/js/global-config/default-config.js');
require('../_common/js/global-config/locale/zh_CN.js');
require('@babel/runtime/helpers/typeof');
require('dayjs');
require('@babel/runtime/helpers/slicedToArray');
require('../utils/render-tnode.js');
require('lodash/isEmpty');
require('lodash/isObject');
require('lodash/camelCase');
require('lodash/kebabCase');
require('../hooks/useTeleport.js');
require('./props.js');
require('./icon/gradient.js');
require('../_common/js/loading/circle-adapter.js');
require('../_common/js/utils/set-style.js');
require('../_common/js/utils/helper.js');
require('@babel/runtime/helpers/toConsumableArray');
require('@babel/runtime/helpers/objectWithoutProperties');
require('lodash/isNull');
require('lodash/isUndefined');
require('lodash/isNumber');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);

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__default["default"](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 = vue.defineComponent({
    setup: function setup() {
      var loadingOptions = vue.reactive(props);
      return {
        loadingOptions: loadingOptions
      };
    },
    render: function render() {
      return vue.h(loading_loading["default"], _objectSpread({}, this.loadingOptions));
    }
  });
  var attach = utils_dom.getAttach(props.attach);
  var loading = vue.createApp(component).mount(document.createElement("div"));
  var parentRelativeClass = hooks_useConfig.usePrefixClass("loading__parent--relative").value;
  var prefixClass = hooks_useConfig.usePrefixClass("loading");
  if (attach) utils_dom.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();
      });
      utils_dom.removeClass(attach, parentRelativeClass);
    }
  };
  return loadingInstance;
}
function produceLoading(props) {
  var lockClass = hooks_useConfig.usePrefixClass("loading--lock");
  if (props === true) {
    fullScreenLoadingInstance = createLoading({
      fullscreen: true,
      loading: true,
      attach: "body"
    });
    return fullScreenLoadingInstance;
  }
  utils_dom.removeClass(document.body, lockClass.value);
  if (props === false) {
    utils_dom.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;
};

exports["default"] = LoadingPlugin;
//# sourceMappingURL=plugin.js.map
