'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
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 _desc, _value, _class; /**
                            * Created by baoyinghai on 11/10/16.
                            */


var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

var _main = require('./main');

var _main2 = _interopRequireDefault(_main);

var _switchContainer = require('./switchContainer');

var _switchContainer2 = _interopRequireDefault(_switchContainer);

var _constant = require('./constant');

var _detailBody = require('./detailBody');

var _detailBody2 = _interopRequireDefault(_detailBody);

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

var _ScrollHelper = require('../../utils/ScrollHelper');

var _LoadingMaskHelper = require('../../utils/LoadingMaskHelper');

var _titleBar = require('../info/titleBar');

var _titleBar2 = _interopRequireDefault(_titleBar);

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

function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }

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 ListDetail = (_class = function (_React$Component) {
  _inherits(ListDetail, _React$Component);

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

    // 检查buttons中是否有保存按钮
    //
    var _this = _possibleConstructorReturn(this, (ListDetail.__proto__ || Object.getPrototypeOf(ListDetail)).call(this, props));

    _this._closeSelectDropDown = function () {
      var tags = document.querySelectorAll('.mx-select-dropdown.mx-select-dropdown--single.mx-select-dropdown-placement-bottomLeft');
      if (tags) {
        tags.forEach(function (item) {
          item.className += ' mx-select-dropdown-hidden';
        });
      }
    };

    _this._getTitleDesc = function () {
      return '';
    };

    _this.getFormFieldsValue = function () {
      /* eslint-disable */
      return _this.refs.detailBody.getFormFieldsValue();
    };

    _this.state = {
      globalBtns: [],
      main: null,
      topButtons: null,
      dataSource: _this.props.dataSource
    };
    return _this;
  }

  _createClass(ListDetail, [{
    key: 'componentWillMount',
    value: function componentWillMount() {
      this.setState({ main: _react2.default.createElement(_detailBody2.default, _extends({}, this.props, { dataSource: this.state.dataSource, createTopButtons: this.createTopButtons, replaceMain: this.replaceMain })) });
    }
  }, {
    key: 'replaceMain',
    value: function replaceMain(actionLink) {
      var _this2 = this;

      var p = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};

      var param = p;

      for (var _len = arguments.length, argv = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
        argv[_key - 2] = arguments[_key];
      }

      if (argv && argv[1]) {
        param = Object.assign({}, param, argv[1]);
      }
      this.props.exec(function () {
        return _this2.props.fetch(actionLink, _extends({}, _this2.props.params, { param: param })).then(function (response) {
          // savePageData(response);
          response.detailResult = Object.assign({}, response.detailResult, param);
          _this2.setState({ dataSource: response });
        });
      });
    }
  }, {
    key: 'componentDidMount',
    value: function componentDidMount() {
      if (this.props.query.s === '1') {
        (0, _ScrollHelper.scrollAble)();
      }
      (0, _LoadingMaskHelper.removeMask)();
    }
  }, {
    key: 'componentWillUnmount',
    value: function componentWillUnmount() {}
  }, {
    key: 'shouldComponentUpdate',
    value: function shouldComponentUpdate(nextProps, nextState) {
      if (nextProps.notShouldUpdate) {
        return false;
      }
      return true;
    }
  }, {
    key: 'createTopButtons',
    value: function createTopButtons(data) {
      this.setState({ topButtons: [].concat(_toConsumableArray(this.state.globalBtns), _toConsumableArray(data)) });
    }
  }, {
    key: 'render',
    value: function render() {
      var detail = _react2.default.createElement(_detailBody2.default, _extends({ ref: 'detailBody' }, this.props, { dataSource: this.state.dataSource, replaceMain: this.replaceMain }));
      // info template will delete query of props;
      if (this.props.query.s === '1') {
        return _react2.default.createElement(
          'div',
          { className: 'detail-wrapper' },
          _react2.default.createElement(_titleBar2.default, { getTitleDesc: this._getTitleDesc }),
          _react2.default.createElement(
            'div',
            { className: 'detail-content-wrapper' },
            detail
          )
        );
      }
      return detail;
    }
  }]);

  return ListDetail;
}(_react2.default.Component), (_applyDecoratedDescriptor(_class.prototype, 'replaceMain', [_coreDecorators.autobind], Object.getOwnPropertyDescriptor(_class.prototype, 'replaceMain'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'createTopButtons', [_coreDecorators.autobind], Object.getOwnPropertyDescriptor(_class.prototype, 'createTopButtons'), _class.prototype)), _class);
exports.default = ListDetail;