'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 _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _NGTCreator = require('./NGTCreator');

var _NGTCreator2 = _interopRequireDefault(_NGTCreator);

var _testObj = require('./testObj');

var _testObj2 = _interopRequireDefault(_testObj);

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/28/17.
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                */


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

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

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

    _this._dispatch = function () {
      var path = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
      var value = arguments[1];

      var last = path.pop();
      path.reduce(function (obj, p) {
        return obj[p];
      }, _this.state)[last] = value;
      _this.setState(_extends({}, _this.state));
    };

    _this.pageGenerator = function (node) {
      if (!node) return null;
      var appendProps = { dispatch: _this._dispatch };
      if (node.childrenNode) {
        appendProps.children = node.childrenNode.map(_this.pageGenerator);
      }
      return node.renderComp(_this.state, appendProps);
    };

    _this.state = _extends({}, _testObj2.default.DSC);
    // this.ART = this.props.ART;
    _this.ART = _testObj2.default.ART;
    _this.NGT = _NGTCreator2.default.ngtCreate(_this.ART);
    return _this;
  }

  _createClass(Page, [{
    key: 'render',
    value: function render() {
      // const { ART } = this.props;
      var Comp = this.pageGenerator(this.NGT);
      return Comp;
    }
  }]);

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

exports.default = Page;