"use strict";

exports.__esModule = true;
exports.useAuthenticationData = exports.default = exports.Wrapper = exports.Loader = exports.Error = void 0;
var _react = _interopRequireDefault(require("react"));
var _styledComponents = _interopRequireWildcard(require("styled-components"));
var _utils = require("../utils");
var _Placeholder = _interopRequireDefault(require("../components/Placeholder"));
var _reactRedux = require("react-redux");
var _authentication = require("../actions/authentication");
var _request = require("../reducers/request");
var _ApplicationModuleLoader = _interopRequireDefault(require("./ApplicationModuleLoader"));
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
(function () {
  var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;
  enterModule && enterModule(module);
})();
(function () {
  var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;
  enterModule && enterModule(module);
})();
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 useAuthenticationData = exports.useAuthenticationData = function useAuthenticationData() {
  return {
    loading: (0, _reactRedux.useSelector)(function (state) {
      return state.getIn(["requests", "actives", _authentication.GET_AUTHENTICATION_PROFILE]);
    }),
    authedUser: (0, _reactRedux.useSelector)(function (state) {
      return state.getIn(["authentication", "name"]);
    }),
    requestError: (0, _utils.unwrapImmutable)((0, _reactRedux.useSelector)(function (state) {
      return state.getIn(["requests", _request.ERROR]) || null;
    })),
    needLogin: (0, _reactRedux.useSelector)(function (state) {
      return state.getIn(["requests", _request.LOGOUT]);
    })
  };
};
__signature__(useAuthenticationData, "useSelector{}\nuseSelector{}\nuseSelector{}\nuseSelector{}", function () {
  return [_reactRedux.useSelector, _reactRedux.useSelector, _reactRedux.useSelector, _reactRedux.useSelector];
});
__signature__(useAuthenticationData, "useSelector{}\nuseSelector{}\nuseSelector{}\nuseSelector{}", function () {
  return [_reactRedux.useSelector, _reactRedux.useSelector, _reactRedux.useSelector, _reactRedux.useSelector];
});
var Wrapper = exports.Wrapper = _styledComponents.default.div.withConfig({
  displayName: "Authenticate__Wrapper",
  componentId: "sc-cw6rn1-0"
})(["display:flex;width:60%;height:100%;padding:0 20vw;flex-direction:column;justify-content:center;"]);
var Loader = exports.Loader = (0, _styledComponents.withTheme)(function (props) {
  return /*#__PURE__*/_react.default.createElement(Wrapper, null, /*#__PURE__*/_react.default.createElement(_Placeholder.default, {
    icon: (0, _utils.getThemeProp)(["icons", "loading"], "loading")(props),
    animate: true
  }));
});
var Error = exports.Error = function Error(_ref) {
  var requestError = _ref.requestError,
    needLogin = _ref.needLogin;
  if (needLogin) {
    return /*#__PURE__*/_react.default.createElement(Wrapper, null, /*#__PURE__*/_react.default.createElement("h1", null, "Not logged in"));
  }
  return /*#__PURE__*/_react.default.createElement(Wrapper, null, /*#__PURE__*/_react.default.createElement("h1", null, (0, _utils.safeGet)(requestError, "payload", "message") || "An error occurred"), "Last failing action: ", /*#__PURE__*/_react.default.createElement("pre", null, JSON.stringify(requestError, null, 2)));
};
var Authenticate = function Authenticate(_ref2) {
  var children = _ref2.children;
  var _useAuthenticationDat = useAuthenticationData(),
    loading = _useAuthenticationDat.loading,
    authedUser = _useAuthenticationDat.authedUser,
    requestError = _useAuthenticationDat.requestError,
    needLogin = _useAuthenticationDat.needLogin;
  if (loading) {
    return /*#__PURE__*/_react.default.createElement(Loader, null);
  }
  if (!authedUser) {
    return /*#__PURE__*/_react.default.createElement(Error, {
      requestError: requestError,
      needLogin: needLogin
    });
  } else {
    return /*#__PURE__*/_react.default.createElement(_ApplicationModuleLoader.default, {
      children: children
    });
  }
};
__signature__(Authenticate, "useAuthenticationData{{ loading, authedUser, requestError, needLogin }}", function () {
  return [useAuthenticationData];
});
__signature__(Authenticate, "useAuthenticationData{{ loading, authedUser, requestError, needLogin }}", function () {
  return [useAuthenticationData];
});
var _default = Authenticate;
var _default2 = _default;
var _default3 = exports.default = _default2;
;
(function () {
  var reactHotLoader = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default : undefined;
  if (!reactHotLoader) {
    return;
  }
  reactHotLoader.register(useAuthenticationData, "useAuthenticationData", "/home/vsts/work/1/s/src/components/Authenticate.js");
  reactHotLoader.register(Wrapper, "Wrapper", "/home/vsts/work/1/s/src/components/Authenticate.js");
  reactHotLoader.register(Loader, "Loader", "/home/vsts/work/1/s/src/components/Authenticate.js");
  reactHotLoader.register(Error, "Error", "/home/vsts/work/1/s/src/components/Authenticate.js");
  reactHotLoader.register(Authenticate, "Authenticate", "/home/vsts/work/1/s/src/components/Authenticate.js");
  reactHotLoader.register(_default, "default", "/home/vsts/work/1/s/src/components/Authenticate.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(useAuthenticationData, "useAuthenticationData", "/home/vsts/work/1/s/src/components/Authenticate.js");
  reactHotLoader.register(Wrapper, "Wrapper", "/home/vsts/work/1/s/src/components/Authenticate.js");
  reactHotLoader.register(Loader, "Loader", "/home/vsts/work/1/s/src/components/Authenticate.js");
  reactHotLoader.register(Error, "Error", "/home/vsts/work/1/s/src/components/Authenticate.js");
  reactHotLoader.register(Authenticate, "Authenticate", "/home/vsts/work/1/s/src/components/Authenticate.js");
  reactHotLoader.register(_default2, "default", "/home/vsts/work/1/s/src/components/Authenticate.js");
})();
;
(function () {
  var leaveModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined;
  leaveModule && leaveModule(module);
})();