'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; /**
                                                                                                                                                                                                                                                                   * 页面跳转
                                                                                                                                                                                                                                                                   */


var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _reactRouterRedux = require('react-router-redux');

var _coreDecorators = require('core-decorators');

var _qs = require('qs');

var _qs2 = _interopRequireDefault(_qs);

var _index = require('../../index');

var _routes = require('../../../framework/entrance/routes');

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

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

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

var _windowUtils = require('../../../framework/utils/windowUtils');

var _StringUtils = require('../../../framework/utils/StringUtils');

var _DispatchService = require('../../../framework/service/DispatchService');

var _dictCodes = require('../../../framework/constant/dictCodes');

var _SessionStorage = require('../../../framework/service/SessionStorage');

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

var jump = function jump(oldParams, actionLink, props, next, stopLoading, linkMappings) {
  var actionLinkMappings = linkMappings || props.actionLinkMappings;
  var params = oldParams;
  if (props.beforeRouterChange) {
    params = props.beforeRouterChange(oldParams);
  }
  params.displayType = props.displayType;
  var templateType = props.templateType || props.domainType;
  var mode = props.interactiveType;
  // console.log('lalal opener', window.opener && window.opener._windowHandler);
  if (mode === _dictCodes.BUTTON_INTERACTIVETYPE.PAGE) {
    var menuIds = (0, _SessionStorage.getRecMenuId)();
    (0, _windowUtils.jumpToNewTab)('/' + _routes.CONTAINER_PRE + (0, _StringUtils.convertTemplate)(actionLink, params, actionLinkMappings) + '?p=' + btoa(_qs2.default.stringify(_extends({}, params, menuIds, { domainType: templateType, s: '1', readonly: props.readonly }))), props);
  } else if (mode === _dictCodes.BUTTON_INTERACTIVETYPE.MODAL || mode === _dictCodes.BUTTON_INTERACTIVETYPE.RIGHTDRAWER) {
    (0, _ModalWrapper.showModal)(_extends({}, params, { s: '', modalTitle: props.buttonDescription, onRefresh: props.onRefresh, readonly: props.readonly }), templateType, (0, _StringUtils.convertTemplate)(actionLink, params, actionLinkMappings), function () {
      return props.onRefresh && props.onRefresh();
    });
  } else if (mode === _dictCodes.BUTTON_INTERACTIVETYPE.PUSH_ELEMENT || mode === _dictCodes.BUTTON_INTERACTIVETYPE.REPLACE && !props.updateMain) {
    (0, _DispatchService.dispatch)((0, _reactRouterRedux.push)({
      pathname: '/' + _routes.CONTAINER_PRE + (0, _StringUtils.convertTemplate)(actionLink, params, actionLinkMappings),
      query: { p: btoa(_qs2.default.stringify(_extends({}, params, { domainType: templateType }))) }
    }));
  } else if (mode === _dictCodes.BUTTON_INTERACTIVETYPE.REPLACE) {
    if (props.updateMain) {
      props.updateMain(actionLink, null, null, _extends({}, params, { domainType: templateType }));
    }
  } else if (mode === _dictCodes.BUTTON_INTERACTIVETYPE.REFRESH) {
    props.onRefresh && props.onRefresh(params);
  } else if (mode === _dictCodes.BUTTON_INTERACTIVETYPE.CANCEL || mode === _dictCodes.BUTTON_INTERACTIVETYPE.GOBACK) {
    window.close();
  }
  if (props.isModal && props.modalCallback) {
    props.modalCallback(); // fresh pre page
  }
  if (props.needCloseCurrentpage === 1) {
    window.close();
  }
  next();
};

exports.default = {
  next: jump
};