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 DialogComponent from "./WDialog";
var defaultOptions = {
  visible: true,
  title: '',
  message: '',
  type: '',
  modalFade: false,
  lockScroll: false,
  skin: 'ios',
  closeOnClickModal: true,
  showConfirmButton: true,
  showCancelButton: false,
  confirmButtonText: '确定',
  cancelButtonText: '取消',
  callback: function callback(action) {
    instance[action === 'confirm' ? 'resolve' : 'reject'](action);
  }
};
var instance;

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

var WDialog = function WDialog(options) {
  options = _objectSpread({}, WDialog.defaultOptions, {}, options);
  return new Promise(function (resolve, reject) {
    if (!instance) {
      createInstance();
    }

    _extends(instance, _objectSpread({
      resolve: resolve,
      reject: reject
    }, options));
  });
};

WDialog.defaultOptions = defaultOptions;

WDialog.alert = function (options) {
  return WDialog(options);
};

WDialog.confirm = function (options) {
  options.showCancelButton = true;
  return WDialog(options);
};

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

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

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

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

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