'use strict';

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

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 _desc, _value, _class; /**
                            * Created by geweimin on 17/3/23.
                            */


var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

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

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; }

function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) {
  var desc = {};
  Object['ke' + 'ys'](descriptor).forEach(function (key) {
    desc[key] = descriptor[key];
  });
  desc.enumerable = !!desc.enumerable;
  desc.configurable = !!desc.configurable;

  if ('value' in desc || desc.initializer) {
    desc.writable = true;
  }

  desc = decorators.slice().reverse().reduce(function (desc, decorator) {
    return decorator(target, property, desc) || desc;
  }, desc);

  if (context && desc.initializer !== void 0) {
    desc.value = desc.initializer ? desc.initializer.call(context) : void 0;
    desc.initializer = undefined;
  }

  if (desc.initializer === void 0) {
    Object['define' + 'Property'](target, property, desc);
    desc = null;
  }

  return desc;
}

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

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

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

    _this.state = {
      dataSource: _this._dealDataSource(_this.props.dataSource, _this.props.fieldsData),
      isOpen: true
    };
    return _this;
  }

  _createClass(ReviseModal, [{
    key: '_dealDataSource',
    value: function _dealDataSource(dataSource, fieldsData) {
      var currentData = dataSource[0];
      var frontData = dataSource[1];
      var resultData = [];
      Object.keys(currentData).forEach(function (item, index) {
        if (currentData[item] !== frontData[item]) {
          var field = fieldsData.filter(function (item1, index1) {
            return item1.name === item;
          })[0];
          resultData.push([field.description + '的值从', frontData[item], '修改为：', currentData[item]]);
        }
      });
      return resultData;
    }
  }, {
    key: '_close',
    value: function _close() {
      this.setState({
        isOpen: false
      });
    }
  }, {
    key: '_open',
    value: function _open() {
      this.setState({
        isOpen: !this.state.isOpen
      });
    }
  }, {
    key: '_renderItem',
    value: function _renderItem(item) {
      return _react2.default.createElement(
        'div',
        null,
        _react2.default.createElement(
          'span',
          null,
          item[0]
        ),
        _react2.default.createElement(
          'span',
          { style: { color: '#40A5ED' } },
          item[1]
        ),
        _react2.default.createElement(
          'span',
          null,
          item[2]
        ),
        _react2.default.createElement(
          'span',
          { style: { color: '#40A5ED' } },
          item[3]
        )
      );
    }
  }, {
    key: 'render',
    value: function render() {
      var _this2 = this;

      var displayStyle = this.state.isOpen ? { width: 320 } : { width: 0 };
      var dataSource = this.state.dataSource;
      return _react2.default.createElement(
        'div',
        null,
        _react2.default.createElement(
          'div',
          { className: 'reviseModal', style: displayStyle },
          _react2.default.createElement(
            'div',
            { style: { height: '100%' } },
            _react2.default.createElement(
              'div',
              { style: { height: '100%', background: '#FFF', border: '1px #ccc solid' } },
              _react2.default.createElement(
                'div',
                { style: { display: 'flex', justifyContent: 'space-between', height: 40, alignItems: 'center', background: '#FFF', borderBottom: '1px #ccc solid' } },
                _react2.default.createElement(
                  'span',
                  { style: { marginLeft: 10 } },
                  '\u4FE1\u606F\u4FEE\u6539\u52A8\u6001'
                ),
                _react2.default.createElement(_mxa.Icon, { className: 'closeBtn', type: 'right-circle', onClick: this._close })
              ),
              _react2.default.createElement(
                'div',
                { style: { paddingTop: 20 } },
                dataSource && dataSource.length > 0 && dataSource.map(function (item, index) {
                  return _react2.default.createElement(
                    'div',
                    { style: { padding: 10 } },
                    _this2._renderItem(item)
                  );
                })
              )
            )
          )
        ),
        _react2.default.createElement(
          'div',
          { className: 'openBtn', onClick: this._open },
          _react2.default.createElement(_mxa.Icon, { type: 'file-text', style: { fontSize: 20, color: '#d8d9dc' } })
        )
      );
    }
  }]);

  return ReviseModal;
}(_react2.default.Component), (_applyDecoratedDescriptor(_class.prototype, '_dealDataSource', [_coreDecorators.autobind], Object.getOwnPropertyDescriptor(_class.prototype, '_dealDataSource'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, '_close', [_coreDecorators.autobind], Object.getOwnPropertyDescriptor(_class.prototype, '_close'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, '_open', [_coreDecorators.autobind], Object.getOwnPropertyDescriptor(_class.prototype, '_open'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, '_renderItem', [_coreDecorators.autobind], Object.getOwnPropertyDescriptor(_class.prototype, '_renderItem'), _class.prototype)), _class);
exports.default = ReviseModal;