'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, _class2, _temp; /**
                                            * Created by baoyinghai on 1/10/17.
                                            */


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

  _createClass(Detail, [{
    key: 'confirmModel',


    /* eslint-disable */
    value: function confirmModel() {
      return this.props.dataSource.displayType || this.props.displayType || this.props.params && this.props.params.displayType;
      return undefined;
    }

    /* eslint-disable */

  }]);

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

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

    _this.state = {
      model: _this.confirmModel() || _this.props.model
    };
    // this.originalOnBeforeUnload = null;
    return _this;
  }

  _createClass(Detail, [{
    key: 'componentWillMount',
    value: function componentWillMount() {
      // this.originalOnBeforeUnload = window.onbeforeunload;
      // window.onbeforeunload = function (e) {
      //   return '关闭提示'; // 这个提示无效
      // };
    }
  }, {
    key: 'componentWillUnmount',
    value: function componentWillUnmount() {
      // window.onbeforeunload =  this.originalOnBeforeUnload;
    }
  }, {
    key: 'getFormFieldsValue',
    value: function getFormFieldsValue() {
      return this.refs.main.getFieldsValue();
    }
  }, {
    key: 'changeState',
    value: function changeState() {
      if (this.state.model === _constant.VIEW) {
        this.setState({ model: _constant.EDIT });
      } else {
        this.setState({ model: _constant.VIEW });
      }
    }
  }, {
    key: 'render',
    value: function render() {
      var model = this.state.model;
      var mainProps = _extends({}, this.props, { model: model });
      var Main = (0, _main2.default)();
      return _react2.default.createElement(Main, _extends({}, mainProps, { ref: 'main', changeState: this.changeState }));
    }
  }]);

  return Detail;
}(_react2.default.Component), _class2.defaultProps = {
  model: _constant.EDIT
}, _class2.propTypes = {
  displayType: _react2.default.PropTypes.oneOf([_constant.VIEW, _constant.EDIT]),
  inject: _react2.default.PropTypes.object,
  createRules: _react2.default.PropTypes.func, // 自定义表单校验 // record
  beforeSubmit: _react2.default.PropTypes.func, // 表单提交之前 // callback
  afterSubmit: _react2.default.PropTypes.func, // 表单提交之后  //  err
  dataSource: _react2.default.PropTypes.object.isRequired,
  renderAnalyser: _react2.default.PropTypes.func, // 自定义渲染标单项 // componentName
  renderButtonsSelf: _react2.default.PropTypes.func // 自定义渲染按钮
}, _temp), (_applyDecoratedDescriptor(_class.prototype, 'confirmModel', [_coreDecorators.autobind], Object.getOwnPropertyDescriptor(_class.prototype, 'confirmModel'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'getFormFieldsValue', [_coreDecorators.autobind], Object.getOwnPropertyDescriptor(_class.prototype, 'getFormFieldsValue'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'changeState', [_coreDecorators.autobind], Object.getOwnPropertyDescriptor(_class.prototype, 'changeState'), _class.prototype)), _class);
exports.default = Detail;