import _extends from "@babel/runtime/helpers/esm/extends";
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (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 = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

import Vue from 'vue';
import TopTipsComponent from "./WTopTips";
import { isObj } from "../../../lib/utils";
var instance;
var defaultOptions = {
  visible: true,
  message: '',
  duration: 3000
};

function parseOptions(params) {
  return isObj(params) ? params : {
    message: params
  };
}

var createInstance = function createInstance() {
  instance = new (Vue.extend(TopTipsComponent))({
    el: document.createElement('div')
  });
  instance.$on('update:visible', function (visible) {
    instance.visible = visible;
  });
  document.body.appendChild(instance.$el);
};

var WTopTips = function WTopTips(options) {
  options = _objectSpread({}, WTopTips.defaultOptions, {}, parseOptions(options));

  if (!instance) {
    createInstance();
  }

  _extends(instance, options);

  clearTimeout(instance.timer);

  _extends(instance, _objectSpread({}, options));

  if (options.duration > 0) {
    instance.timer = setTimeout(function () {
      instance.visible = false;
    }, options.duration);
  }

  return instance;
};

WTopTips.defaultOptions = defaultOptions;

WTopTips.close = function () {
  if (instance) {
    instance.visible = false;
  }
};

WTopTips.setDefaultOptions = function (options) {
  WTopTips.defaultOptions = _objectSpread({}, defaultOptions, {}, options);
};

WTopTips.resetDefaultOptions = function () {
  WTopTips.defaultOptions = defaultOptions;
};

WTopTips.install = function () {// TODO
};

Vue.prototype.$toptips = WTopTips;
export { WTopTips };
export default WTopTips;
//# sourceMappingURL=index.js.map