'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.FlowSetting = exports.default = undefined;

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 _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

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

var _IconHelper = require('../../../../framework/utils/IconHelper');

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

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

var _ProcessHelper = require('../../../../framework/utils/ProcessHelper');

var _CacheService = require('../../../../framework/service/CacheService');

var _MenuHelper = require('../../../../framework/utils/MenuHelper');

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

require('./chart-flow.less');

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

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /**
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                * Created by baoyinghai on 6/9/17.
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                */


var reg = /^(.*\w+)(Review|Apply)(List\/.*)$/;

var TabPane = _mxa.Tabs.TabPane;

var FLOW_TYPE = {
  ApplyToDo: '待处理',
  ApplyReturn: '被退回',
  ReviewToDo: '待审核'
};

var FlowComp = function (_React$Component) {
  _inherits(FlowComp, _React$Component);

  function FlowComp(props) {
    _classCallCheck(this, FlowComp);

    var _this = _possibleConstructorReturn(this, (FlowComp.__proto__ || Object.getPrototypeOf(FlowComp)).call(this, props));

    _this._changeToNormalLink = function (link) {
      return link.replace(reg, "$1Review$3");
    };

    _this._getMenuBindParameters = function (link) {
      var ret = {};
      if ((0, _ProcessHelper.isApply)(link)) {
        ret.menu = 'BPMApply.QueryToDo';
      } else if ((0, _ProcessHelper.isReview)(link)) {
        ret.menu = 'BPMReview.QueryToDo';
      }
      return ret;
    };

    _this.jumpToFlow = function (uri) {
      var hyperLink = uri; // this._changeToNormalLink(uri);// hyperLink.replace();

      var _getMenuItemAndPathBy = (0, _MenuHelper.getMenuItemAndPathByFunc)(function (item) {
        return item.actionLink === hyperLink;
      }, (0, _CacheService.getMenu)()),
          linkInfo = _getMenuItemAndPathBy.linkInfo;

      if (!linkInfo) {
        console.log('menu info is null!!');
        return;
      }
      var bindParameters = _this._getMenuBindParameters(hyperLink);
      (0, _SessionStorage.saveProcessMenuCode)(bindParameters.menu);
      (0, _SessionStorage.saveEnterMenuId)(linkInfo.menuCode);
      (0, _DispatchService.dispatch)((0, _reactRouterRedux.push)({ pathname: '/' + _routes.CONTAINER_PRE + hyperLink, state: _extends({}, bindParameters) }));
    };

    _this.renderTab = function (type, index) {
      var _this$props$dataSourc = _this.props.dataSource,
          dataSource = _this$props$dataSourc === undefined ? [] : _this$props$dataSourc;

      var data = dataSource.filter(function (d) {
        return d.taskType === type;
      });
      return _react2.default.createElement(
        TabPane,
        { tab: FLOW_TYPE[type], key: index },
        _react2.default.createElement(
          'div',
          { className: 'task-wrapper' },
          _react2.default.createElement(
            'div',
            { className: 'content-wrapper' },
            data.map(function (record) {
              return _react2.default.createElement(
                'div',
                { className: 'one-record-wrapper', onClick: function onClick() {
                    return _this.jumpToFlow(record.hyperLink);
                  } },
                _react2.default.createElement(
                  'div',
                  { className: 'one-record' },
                  _react2.default.createElement(
                    'span',
                    { className: 'desc' },
                    record.comment
                  ),
                  (0, _IconHelper.iconWrapper)('icon-arrow'),
                  record.quantity && _react2.default.createElement(
                    'div',
                    { className: 'item-num' },
                    record.quantity
                  )
                )
              );
            })
          )
        )
      );
    };

    _this._onChange = function (e) {
      _this.setState({
        activeKey: e
      });
    };

    _this.state = {
      activeKey: "0"
    };
    return _this;
  }

  _createClass(FlowComp, [{
    key: 'render',
    value: function render() {
      return _react2.default.createElement(
        _mxa.Tabs,
        { defaultActiveKey: this.state.activeKey, size: 'small', onChange: this._onChange },
        Object.keys(FLOW_TYPE).map(this.renderTab)
      );
    }
  }]);

  return FlowComp;
}(_react2.default.Component);

// const keyMap = {
//   // x: 'x轴',
//   // y: 'y轴',
//   // lname: '折线标题'
//   desc: '描述字段名',
//   flowType: '流程类型字段名',
//   actionLink: '链接地址'
// };

exports.default = FlowComp;
var FlowSetting = exports.FlowSetting = {
  getKeys: function getKeys(keys) {
    return [];
  }
};