/**
 * ldesign v0.2.3
 * (c) 2022年9月24日 swimly
 * @license MIT
 */

'use strict';

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

var Vue = require('vue');
var components_loading_loading = require('./loading.js');
var config = require('../../config.js');
var utils_dom = require('../../utils/dom.js');
require('./icon/gradient.js');
require('../../chunks/defineProperty-56324511.js');
require('../../chunks/set-style.js');
require('../../chunks/helper2.js');
require('../../utils/render-node.js');
require('lodash/camelCase');
require('lodash/kebabCase');
require('../../utils/transfer-dom.js');
require('./props.js');
require('../config-provider/config-receiver.js');
require('lodash/mergeWith');
require('lodash');
require('../config-provider/context.js');
require('../../chunks/zh_CN.js');
require('../../utils/mixins.js');
require('raf');
require('lodash/isString');
require('../../utils/easing.js');

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

var Vue__default = /*#__PURE__*/_interopDefaultLegacy(Vue);

const lockClass = `${config.PREFIX}-loading--lock`;
let fullScreenLoadingInstance = null;

function createLoading(options) {
  const props = { ...options
  };
  const loading = new components_loading_loading["default"]({
    propsData: { ...props
    }
  }).$mount();
  const attach = utils_dom.getAttach(props.attach);

  if (attach) {
    attach.appendChild(loading.$el);
  } else {
    console.error("attach is not exist");
  }

  const loadingInstance = {
    hide: () => {
      loading.loading = false;
      loading.$el.parentNode.removeChild(loading.$el);
    }
  };
  return loadingInstance;
}

function produceLoading(props) {
  if (props === true) {
    fullScreenLoadingInstance = createLoading({
      fullscreen: true,
      loading: true,
      attach: "body"
    });
    return fullScreenLoadingInstance;
  }

  if (props === false) {
    utils_dom.removeClass(document.body, lockClass);
    fullScreenLoadingInstance.hide();
    fullScreenLoadingInstance = null;
    return;
  }

  return createLoading(props);
}

const LoadingPlugin = produceLoading;

LoadingPlugin.install = () => {
  Vue__default["default"].prototype.$loading = produceLoading;
};

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