"use strict";

exports.__esModule = true;
exports.default = exports.ViewPort = exports.Base = void 0;

var _react = _interopRequireWildcard(require("react"));

var _reactIntl = require("react-intl");

var _propTypes = _interopRequireDefault(require("prop-types"));

var _styledComponents = _interopRequireWildcard(require("styled-components"));

var _reactRedux = require("react-redux");

var _utils = require("../../utils");

var _applications = require("../../actions/applications");

var _useToggle3 = _interopRequireDefault(require("../../hooks/useToggle"));

var _useLoader = _interopRequireDefault(require("../../hooks/useLoader"));

var _applications2 = require("../../selectors/applications");

var _Text = require("../Text");

var _Scope = _interopRequireWildcard(require("../Scope"));

var _Topbar = _interopRequireDefault(require("./Topbar"));

var _Sidebar = _interopRequireDefault(require("./Sidebar"));

var _About = _interopRequireDefault(require("./About"));

var _Preferences = _interopRequireWildcard(require("./Preferences"));

var _ConnectedToastList = _interopRequireDefault(require("./ConnectedToastList"));

var _useApplicationHelpUrl = _interopRequireDefault(require("./useApplicationHelpUrl"));

var _useViewState3 = _interopRequireDefault(require("../../hooks/useViewState"));

var _versionInfo = require("../../actions/versionInfo");

var _locale = require("../../selectors/locale");

var _navigation = require("../../selectors/navigation");

var _loadingScreen = _interopRequireDefault(require("../MaterialUI/Feedback/loadingScreen"));

var _sharedMessages = _interopRequireDefault(require("../../sharedMessages"));

var _ActionModal = _interopRequireDefault(require("../MaterialUI/DataDisplay/PredefinedElements/ActionModal"));

var _requests = require("../../selectors/requests");

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

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

(function () {
  var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;
  enterModule && enterModule(module);
})();

(function () {
  var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;
  enterModule && enterModule(module);
})();

function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }

function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }

function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }

function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }

function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default.signature : function (a) {
  return a;
};

var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default.signature : function (a) {
  return a;
};

var Base = _styledComponents.default.div.withConfig({
  displayName: "AppFrame__Base",
  componentId: "sc-1no0pw0-0"
})(["background-color:", ";height:100%;overflow:hidden;", ";"], (0, _utils.getThemeProp)(["colors", "bgDark"], "#333333"), (0, _utils.ifFlag)("preferencesOpen", (0, _styledComponents.css)(["pointer-events:none;"])));

exports.Base = Base;

var ViewPort = _styledComponents.default.div.withConfig({
  displayName: "AppFrame__ViewPort",
  componentId: "sc-1no0pw0-1"
})(["overflow:hidden;background-color:white;border-top-left-radius:10px;height:calc(100% - 40px);width:calc(100% - 50px);position:absolute;bottom:0;right:0;display:flex;flex-direction:column;transition:width 0.3s ease-out;", ";"], (0, _utils.ifFlag)("open", (0, _styledComponents.css)(["width:calc(100% - 200px);"])));

exports.ViewPort = ViewPort;

var getApp = function getApp(apps, id) {
  return apps.filter(function (app) {
    return app.name === id;
  })[0];
};

var AppFrame = function AppFrame(_ref) {
  var initOpen = _ref.initOpen,
      applicationId = _ref.applicationId,
      modules = _ref.modules,
      activeModules = _ref.activeModules,
      children = _ref.children,
      noScope = _ref.noScope,
      _ref$forceShowScope = _ref.forceShowScope,
      forceShowScope = _ref$forceShowScope === void 0 ? [] : _ref$forceShowScope;

  var _useIntl = (0, _reactIntl.useIntl)(),
      formatMessage = _useIntl.formatMessage;

  var locale = (0, _reactRedux.useSelector)(_locale.currentLocale);
  var needLogin = (0, _reactRedux.useSelector)(_requests.logoutSelector);
  var applications = (0, _utils.unwrapImmutable)((0, _reactRedux.useSelector)(_applications2.localizedAppSelector));
  var moduleName = (0, _reactRedux.useSelector)(_navigation.selectCurrentModuleName);

  var _useApplicationHelpUr = (0, _useApplicationHelpUrl.default)(applicationId),
      _useApplicationHelpUr2 = _slicedToArray(_useApplicationHelpUr, 1),
      helpUrl = _useApplicationHelpUr2[0];

  (0, _useLoader.default)((0, _applications.getApplications)(), function (state) {
    return (0, _applications2.localizedAppSelector)(state).size;
  });

  var _useToggle = (0, _useToggle3.default)(initOpen),
      _useToggle2 = _slicedToArray(_useToggle, 3),
      open = _useToggle2[0],
      toggle = _useToggle2[1],
      reset = _useToggle2[2];

  var currentApplication = getApp(applications, applicationId);
  (0, _useLoader.default)((0, _versionInfo.getVersionInfo)(locale), function () {
    return locale === null || helpUrl !== null;
  });

  var _React$useState = _react.default.useState(false),
      _React$useState2 = _slicedToArray(_React$useState, 2),
      doesApplicationNeedRefresh = _React$useState2[0],
      setDoesApplicationNeedRefresh = _React$useState2[1];

  var reloadApplication = function reloadApplication() {
    window.location.reload();
    setDoesApplicationNeedRefresh(false);
  };

  (0, _react.useEffect)(function () {
    if (needLogin) {
      setDoesApplicationNeedRefresh(true);
    }
  }, [needLogin]);
  (0, _react.useEffect)(function () {
    document.title = (currentApplication == null ? void 0 : currentApplication.displayName) || applicationId;
  }, [currentApplication, applicationId]);

  var _useViewState = (0, _useViewState3.default)(_Preferences.PREFS_NAME),
      _useViewState2 = _slicedToArray(_useViewState, 1),
      prefViewState = _useViewState2[0];

  return /*#__PURE__*/_react.default.createElement(Base, {
    preferencesOpen: prefViewState.show
  }, /*#__PURE__*/_react.default.createElement(_ConnectedToastList.default, null), /*#__PURE__*/_react.default.createElement(_ActionModal.default, {
    title: formatMessage(_sharedMessages.default.error),
    message: formatMessage(_sharedMessages.default.needToRefresh),
    open: doesApplicationNeedRefresh,
    actions: [{
      label: _sharedMessages.default.refresh,
      handler: reloadApplication,
      isPrimary: true
    }]
  }), /*#__PURE__*/_react.default.createElement(_Topbar.default, {
    applications: applications,
    applicationId: applicationId,
    currentApplication: currentApplication,
    helpUrl: helpUrl,
    onClick: reset
  }), /*#__PURE__*/_react.default.createElement(_Sidebar.default, {
    open: open,
    toggle: toggle,
    modules: modules,
    activeModules: activeModules
  }), /*#__PURE__*/_react.default.createElement(ViewPort, {
    open: open,
    onClick: reset
  }, noScope && !forceShowScope.includes(moduleName) ? /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_Scope.Bar, null), children) : /*#__PURE__*/_react.default.createElement(_Scope.default, null, children)), /*#__PURE__*/_react.default.createElement(_About.default, {
    currentApplication: currentApplication
  }), /*#__PURE__*/_react.default.createElement(_loadingScreen.default, null), /*#__PURE__*/_react.default.createElement(_Preferences.default, null));
};

__signature__(AppFrame, "useIntl{{ formatMessage }}\nuseSelector{locale}\nuseSelector{needLogin}\nuseSelector{}\nuseSelector{moduleName}\nuseApplicationHelpUrl{[helpUrl]}\nuseLoader{}\nuseToggle{[open, toggle, reset]}\nuseLoader{}\nuseState{[doesApplicationNeedRefresh, setDoesApplicationNeedRefresh](false)}\nuseEffect{}\nuseEffect{}\nuseViewState{[prefViewState]}", function () {
  return [_reactIntl.useIntl, _reactRedux.useSelector, _reactRedux.useSelector, _reactRedux.useSelector, _reactRedux.useSelector, _useApplicationHelpUrl.default, _useLoader.default, _useToggle3.default, _useLoader.default, _useViewState3.default];
});

__signature__(AppFrame, "useIntl{{ formatMessage }}\nuseSelector{locale}\nuseSelector{needLogin}\nuseSelector{}\nuseSelector{moduleName}\nuseApplicationHelpUrl{[helpUrl]}\nuseLoader{}\nuseToggle{[open, toggle, reset]}\nuseLoader{}\nuseState{[doesApplicationNeedRefresh, setDoesApplicationNeedRefresh](false)}\nuseEffect{}\nuseEffect{}\nuseViewState{[prefViewState]}", function () {
  return [_reactIntl.useIntl, _reactRedux.useSelector, _reactRedux.useSelector, _reactRedux.useSelector, _reactRedux.useSelector, _useApplicationHelpUrl.default, _useLoader.default, _useToggle3.default, _useLoader.default, _useViewState3.default];
});

AppFrame.displayName = "AppFrame";
AppFrame.propTypes = {
  applicationId: _propTypes.default.string.isRequired,
  modules: _propTypes.default.array.isRequired,
  activeModules: _propTypes.default.objectOf(_propTypes.default.oneOfType([_propTypes.default.bool, _propTypes.default.shape({
    type: _propTypes.default.string,
    message: _Text.ptLabel
  })])),
  noScope: _propTypes.default.bool
};
var _default = AppFrame;
var _default2 = _default;
var _default3 = _default2;
exports.default = _default3;
;

(function () {
  var reactHotLoader = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default : undefined;

  if (!reactHotLoader) {
    return;
  }

  reactHotLoader.register(Base, "Base", "/home/vsts/work/1/s/src/components/AppFrame/AppFrame.js");
  reactHotLoader.register(ViewPort, "ViewPort", "/home/vsts/work/1/s/src/components/AppFrame/AppFrame.js");
  reactHotLoader.register(getApp, "getApp", "/home/vsts/work/1/s/src/components/AppFrame/AppFrame.js");
  reactHotLoader.register(AppFrame, "AppFrame", "/home/vsts/work/1/s/src/components/AppFrame/AppFrame.js");
  reactHotLoader.register(_default, "default", "/home/vsts/work/1/s/src/components/AppFrame/AppFrame.js");
})();

;

(function () {
  var leaveModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined;
  leaveModule && leaveModule(module);
})();

;

(function () {
  var reactHotLoader = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default : undefined;

  if (!reactHotLoader) {
    return;
  }

  reactHotLoader.register(Base, "Base", "/home/vsts/work/1/s/src/components/AppFrame/AppFrame.js");
  reactHotLoader.register(ViewPort, "ViewPort", "/home/vsts/work/1/s/src/components/AppFrame/AppFrame.js");
  reactHotLoader.register(getApp, "getApp", "/home/vsts/work/1/s/src/components/AppFrame/AppFrame.js");
  reactHotLoader.register(AppFrame, "AppFrame", "/home/vsts/work/1/s/src/components/AppFrame/AppFrame.js");
  reactHotLoader.register(_default2, "default", "/home/vsts/work/1/s/src/components/AppFrame/AppFrame.js");
})();

;

(function () {
  var leaveModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined;
  leaveModule && leaveModule(module);
})();