/**
 * tdesign v0.39.1-alpha.1
 * (c) 2022 tdesign
 * @license MIT
 */

'use strict';

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

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var Vue = require('vue');
var loading_loading = require('./loading.js');
var config = require('../config.js');
var utils_dom = require('../utils/dom.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/objectWithoutProperties');
require('@babel/runtime/helpers/slicedToArray');
require('../utils/classnames.js');
require('../utils/render-tnode.js');
require('@babel/runtime/helpers/typeof');
require('lodash/isObject');
require('../utils/transfer-dom.js');
require('./props.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 _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
var Vue__default = /*#__PURE__*/_interopDefaultLegacy(Vue);

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 lockClass = "".concat(config.prefix, "-loading--lock");
var fullScreenLoadingInstance = null;

function createLoading(options) {
  var props = _objectSpread({}, options);

  var loading = new loading_loading["default"]({
    propsData: _objectSpread({}, props)
  }).$mount();
  var attach = utils_dom.getAttach(props.attach);

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

  var loadingInstance = {
    hide: function 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);
}

var LoadingPlugin = produceLoading;

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

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