'use strict';

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

var _regenerator = require('babel-runtime/regenerator');

var _regenerator2 = _interopRequireDefault(_regenerator);

var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator');

var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);

var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

var _createClass2 = require('babel-runtime/helpers/createClass');

var _createClass3 = _interopRequireDefault(_createClass2);

var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');

var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);

var _inherits2 = require('babel-runtime/helpers/inherits');

var _inherits3 = _interopRequireDefault(_inherits2);

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _IntlManager = require('../master/IntlManager');

var _IntlManager2 = _interopRequireDefault(_IntlManager);

var _axios = require('../axios');

var _axios2 = _interopRequireDefault(_axios);

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

var ModuleWrapper = function (_Component) {
  (0, _inherits3['default'])(ModuleWrapper, _Component);

  function ModuleWrapper() {
    var _ref;

    var _temp, _this, _ret;

    (0, _classCallCheck3['default'])(this, ModuleWrapper);

    for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    return _ret = (_temp = (_this = (0, _possibleConstructorReturn3['default'])(this, (_ref = ModuleWrapper.__proto__ || Object.getPrototypeOf(ModuleWrapper)).call.apply(_ref, [this].concat(args))), _this), _this.state = {
      loading: true
    }, _temp), (0, _possibleConstructorReturn3['default'])(_this, _ret);
  }

  (0, _createClass3['default'])(ModuleWrapper, [{
    key: 'componentDidMount',
    value: function componentDidMount() {
      this.registryIntl();
    }
  }, {
    key: 'registryIntl',
    value: function () {
      var _ref2 = (0, _asyncToGenerator3['default'])( /*#__PURE__*/_regenerator2['default'].mark(function _callee() {
        var moduleCode, intlManager, res;
        return _regenerator2['default'].wrap(function _callee$(_context) {
          while (1) {
            switch (_context.prev = _context.next) {
              case 0:
                moduleCode = this.props.moduleCode;
                intlManager = (0, _IntlManager2['default'])();


                this.setState({ loading: true });
                _context.prev = 3;
                _context.next = 6;
                return _axios2['default'].post('/common/prompt/' + moduleCode, {});

              case 6:
                res = _context.sent;

                intlManager.add(res || {});
                _context.next = 13;
                break;

              case 10:
                _context.prev = 10;
                _context.t0 = _context['catch'](3);

                intlManager.add({});

              case 13:
                _context.prev = 13;

                this.setState({ loading: false });
                return _context.finish(13);

              case 16:
              case 'end':
                return _context.stop();
            }
          }
        }, _callee, this, [[3, 10, 13, 16]]);
      }));

      function registryIntl() {
        return _ref2.apply(this, arguments);
      }

      return registryIntl;
    }()
  }, {
    key: 'render',
    value: function render() {
      var loading = this.state.loading;
      var children = this.props.children;


      return loading ? null : children;
    }
  }]);
  return ModuleWrapper;
}(_react.Component);

exports['default'] = ModuleWrapper;