'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.popConfirm = exports.popAlert = exports.closeWhileClickSpace = exports.fetch = exports.popModal = undefined;

var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; /**
                                                                                                                                                                                                                                                                               * Created by baoyinghai on 5/26/17.
                                                                                                                                                                                                                                                                               */


var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _ModalWrapper = require('../../../framework/pageContainer/ModalWrapper');

var _fetch = require('../../../framework/system/fetch');

var _longRunOpt = require('../../../framework/system/longRunOpt');

var _clickSpaceCallback = require('../../clickSpaceCallback');

var _mxa = require('../../mxa');

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var popModal = exports.popModal = function popModal(modalTitle, body) {
  (0, _ModalWrapper.showModal)({ modalTitle: modalTitle, body: body });
};

var fetch = exports.fetch = function fetch(url, params, success, fail) {
  (0, _longRunOpt.longRunExec)(function () {
    return (0, _fetch.PFetch)(url, params).then(success).catch(fail);
  });
};

var closeWhileClickSpace = exports.closeWhileClickSpace = _clickSpaceCallback.clickSpaceWrapper;

var getDescOfResponse = function getDescOfResponse(msg) {
  if (typeof msg === 'string') {
    return msg;
  }
  if ((typeof msg === 'undefined' ? 'undefined' : _typeof(msg)) === 'object') {
    return msg && msg.msgContent || JSON.stringify(msg);
  }
  return msg;
};

var popAlert = exports.popAlert = function popAlert(msg, ok, cancel) {
  var config = {
    title: '提示',
    content: _react2.default.createElement(
      'div',
      null,
      getDescOfResponse(msg)
    )
  };
  ok ? config.onOk = ok : null;
  cancel ? config.onCancel = cancel : null;
  _mxa.Modal.info(config);
};

var popConfirm = exports.popConfirm = function popConfirm(msg, ok, cancel) {
  var config = {
    title: '提示',
    content: _react2.default.createElement(
      'div',
      null,
      getDescOfResponse(msg)
    )
  };
  ok ? config.onOk = ok : null;
  cancel ? config.onCancel = cancel : null;
  _mxa.Modal.confirm(config);
};