"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = exports.alert = void 0;

var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));

var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));

var _bem = require("@zarm-design/bem");

var _configProvider = require("../config-provider");

var _methods = require("./methods");

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(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

var alert = function alert(props) {
  var className = props.className,
      _props$animationType = props.animationType,
      animationType = _props$animationType === void 0 ? 'zoom' : _props$animationType,
      confirmText = props.confirmText,
      onConfirm = props.onConfirm,
      rest = (0, _objectWithoutProperties2.default)(props, ["className", "animationType", "confirmText", "onConfirm"]);

  var _getRuntimeConfig = (0, _configProvider.getRuntimeConfig)(),
      prefixCls = _getRuntimeConfig.prefixCls,
      locale = _getRuntimeConfig.locale;

  var bem = (0, _bem.createBEM)('alert', {
    prefixCls: prefixCls
  });
  return new Promise(function (resolve) {
    var _show = (0, _methods.show)(_objectSpread(_objectSpread({}, rest), {}, {
      className: bem([className]),
      animationType: animationType,
      actions: [{
        text: confirmText || (locale === null || locale === void 0 ? void 0 : locale.Modal.confirmText),
        onClick: function () {
          var _onClick = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
            var _props$onConfirm;

            var result;
            return _regenerator.default.wrap(function _callee$(_context) {
              while (1) {
                switch (_context.prev = _context.next) {
                  case 0:
                    _context.next = 2;
                    return (_props$onConfirm = props.onConfirm) === null || _props$onConfirm === void 0 ? void 0 : _props$onConfirm.call(props);

                  case 2:
                    result = _context.sent;

                    if (!(result === false)) {
                      _context.next = 5;
                      break;
                    }

                    return _context.abrupt("return");

                  case 5:
                    close();
                    resolve(null);

                  case 7:
                  case "end":
                    return _context.stop();
                }
              }
            }, _callee);
          }));

          function onClick() {
            return _onClick.apply(this, arguments);
          }

          return onClick;
        }()
      }]
    })),
        close = _show.close;
  });
};

exports.alert = alert;
var _default = alert;
exports.default = _default;