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

import Vue from 'vue';
import _Loading from './loading.js';
import { PREFIX } from '../../config.js';
import { removeClass, getAttach } from '../../utils/dom.js';
import './icon/gradient.js';
import '../../_chunks/dep-1dd6d50e.js';
import '../../_chunks/dep-1aed710a.js';
import '../../_chunks/dep-d640115b.js';
import '../../utils/render-node.js';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import '../../utils/transfer-dom.js';
import './props.js';
import '../config-provider/config-receiver.js';
import 'lodash/mergeWith';
import 'lodash';
import '../config-provider/context.js';
import '../../_chunks/dep-b1584b65.js';
import '../../utils/mixins.js';
import 'raf';
import 'lodash/isString';
import '../../utils/easing.js';

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

function createLoading(options) {
  const props = { ...options
  };
  const loading = new _Loading({
    propsData: { ...props
    }
  }).$mount();
  const attach = 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) {
    removeClass(document.body, lockClass);
    fullScreenLoadingInstance.hide();
    fullScreenLoadingInstance = null;
    return;
  }

  return createLoading(props);
}

const LoadingPlugin = produceLoading;

LoadingPlugin.install = () => {
  Vue.prototype.$loading = produceLoading;
};

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