"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard")["default"];
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/slicedToArray"));
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/createClass"));
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/inherits"));
var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/createSuper"));
var _react = _interopRequireWildcard(require("react"));
var _reactRedux = require("react-redux");
var _rudyMatchPath = _interopRequireDefault(require("rudy-match-path"));
var _router = require("@reach/router");
var _bundleCommon = require("@kineticdata/bundle-common");
var _immutable = require("immutable");
var _store = require("./redux/store");
var _app = require("./redux/modules/app");
var _App = require("./App");
var _default = exports["default"] = /*#__PURE__*/function (_Component) {
  (0, _inherits2["default"])(_default, _Component);
  var _super = (0, _createSuper2["default"])(_default);
  function _default(props) {
    var _this;
    (0, _classCallCheck2["default"])(this, _default);
    _this = _super.call(this, props);
    _this.state = {
      ready: false
    };
    // Listen to the local store to see if the embedded app is ready to be
    // re-rendered. Currently this just means that the required props have been
    // synced into the local store.
    _this.unsubscribe = _store.store.subscribe(function () {
      var ready = _store.store.getState().app.ready;
      if (ready !== _this.state.ready) {
        _this.setState({
          ready: ready
        });
      }
    });
    return _this;
  }
  (0, _createClass2["default"])(_default, [{
    key: "componentDidMount",
    value: function componentDidMount() {
      Object.entries(this.props.appState).forEach(_app.syncAppState);
    }
  }, {
    key: "componentDidUpdate",
    value: function componentDidUpdate(prevProps) {
      Object.entries(this.props.appState).filter(function (_ref) {
        var _ref2 = (0, _slicedToArray2["default"])(_ref, 2),
          key = _ref2[0],
          value = _ref2[1];
        return !(0, _immutable.is)(value, prevProps.appState[key]);
      }).forEach(_app.syncAppState);
    }
  }, {
    key: "componentWillUnmount",
    value: function componentWillUnmount() {
      this.unsubscribe();
    }
  }, {
    key: "render",
    value: function render() {
      return this.state.ready && /*#__PURE__*/_react["default"].createElement(_reactRedux.Provider, {
        store: _store.store,
        context: _store.context
      }, /*#__PURE__*/_react["default"].createElement(_bundleCommon.CommonProvider, null, /*#__PURE__*/_react["default"].createElement(_router.LocationProvider, {
        hashRouting: true,
        history: _store.connectedHistory
      }, /*#__PURE__*/_react["default"].createElement(_bundleCommon.ToastsContainer, {
        duration: 5000
      }), /*#__PURE__*/_react["default"].createElement(_bundleCommon.ModalFormContainer, null), /*#__PURE__*/_react["default"].createElement(_router.Router, null, /*#__PURE__*/_react["default"].createElement(_App.App, {
        render: this.props.render,
        path: "".concat(this.props.appState.location, "/*")
      })))));
    }
  }]);
  return _default;
}(_react.Component);
_default.shouldHideHeader = function (_ref3) {
  var appLocation = _ref3.appLocation,
    location = _ref3.location;
  return (0, _rudyMatchPath["default"])(location.pathname, {
    path: "".concat(appLocation, "/display")
  });
};
_default.shouldHideSidebar = function (_ref4) {
  var appLocation = _ref4.appLocation,
    location = _ref4.location;
  return (0, _rudyMatchPath["default"])(location.pathname, {
    path: "".concat(appLocation, "/display")
  });
};
// Set to true if package allows public (unauthenticated) routes
_default.hasPublicRoutes = false;
// Class that will be added to the body when this package is rendered
_default.bodyClassName = 'package--tech-bar';
// Relative route to package settings page
_default.settingsRoute = '/settings';