import "core-js/modules/web.dom.iterable";
import _Promise from "@babel/runtime-corejs2/core-js/promise";
import _Object$getOwnPropertyDescriptor from "@babel/runtime-corejs2/core-js/object/get-own-property-descriptor";
import _Object$assign from "@babel/runtime-corejs2/core-js/object/assign";
import _inheritsLoose from "../../inheritsLoose";
import _defineProperty from "@babel/runtime-corejs2/helpers/defineProperty";
import _applyDecoratedDescriptor from "@babel/runtime-corejs2/helpers/applyDecoratedDescriptor";
import Intact, { normalize } from 'intact-angular';
import template from './alert.vdt';
export default function addStaticMethods(Dialog) {
  var _dec, _class, _init, _class2, _temp;

  var AlertDialog = (_dec = Intact.template(), (_class = (_temp = _class2 =
  /*#__PURE__*/
  function (_Dialog) {
    _inheritsLoose(AlertDialog, _Dialog);

    function AlertDialog() {
      return _Dialog.apply(this, arguments) || this;
    }

    var _proto = AlertDialog.prototype;

    _proto.defaults = function defaults() {
      return _Object$assign({}, _Dialog.prototype.defaults.call(this), {
        title: undefined,
        content: undefined,
        type: 'success',
        size: 'mini',
        hideIcon: false,
        hideFooter: false,
        showClose: false,
        _title: undefined
      });
    };

    return AlertDialog;
  }(Dialog), _defineProperty(_class2, "template", template), _temp), (_applyDecoratedDescriptor(_class, "template", [_dec], (_init = _Object$getOwnPropertyDescriptor(_class, "template"), _init = _init ? _init.value : undefined, {
    enumerable: true,
    configurable: true,
    writable: true,
    initializer: function initializer() {
      return _init;
    }
  }), _class)), _class));

  function show(options) {
    if (options === void 0) {
      options = {};
    }

    return new _Promise(function (resolve, reject) {
      var dialog = new AlertDialog(options);
      dialog.show();
      dialog.on('ok', function () {
        resolve();
      });
      dialog.on('cancel', function () {
        reject();
      }); // if press esc, treat it as cancel too

      dialog.on('terminate', function () {
        reject();
      });
    });
  }

  ['success', 'warning', 'error', 'confirm'].forEach(function (type) {
    Dialog[type] = function (options) {
      if (options === void 0) {
        options = {};
      }

      options = _Object$assign({}, options, {
        type: type
      });

      if (options.title) {
        options._title = options.title;
        delete options.title;
      }

      options.closable = options.escClosable = type === 'confirm';
      return show(options);
    };
  });
}