"use strict";

require("core-js/modules/web.dom-collections.iterator.js");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

require("core-js/modules/es.promise.js");

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

var _AuthScreenModule = _interopRequireDefault(require("./AuthScreen.module.scss"));

var _antd = require("antd");

require("antd/dist/antd.css");

var _SignupForm = _interopRequireDefault(require("../SignupForm/SignupForm"));

var _SigninForm = _interopRequireDefault(require("../SigninForm/SigninForm"));

var _Featuredescriptioncarousel = _interopRequireDefault(require("../Featuredescriptioncarousel/Featuredescriptioncarousel"));

var _reactResponsive = require("react-responsive");

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

var _localforage = _interopRequireDefault(require("localforage"));

var _reactRouterDom = require("react-router-dom");

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; }

//import Socialmediasignup from "../Socialmediasignup/Socialmediasignup";
const AuthScreen = props => {
  const navigate = (0, _reactRouterDom.useNavigate)();
  const isDesktopOrLaptop = (0, _reactResponsive.useMediaQuery)({
    query: "(min-width: 980px)"
  });
  (0, _react.useEffect)(() => {
    const handleAuthenticateStatus = async () => {
      const dbInitialData = await _localforage.default.getItem("userDetails");
      const accessToken = sessionStorage.getItem("access_token");
      const refreshToken = sessionStorage.getItem("refresh_token");

      if (dbInitialData !== null && accessToken !== null && refreshToken !== null) {
        navigate("/chat");
      }
    };

    handleAuthenticateStatus();
  }, []);
  return /*#__PURE__*/_react.default.createElement("div", {
    className: _AuthScreenModule.default.AuthScreen
  }, /*#__PURE__*/_react.default.createElement("div", {
    className: _AuthScreenModule.default.AuthScreen__formContainer
  }, /*#__PURE__*/_react.default.createElement(_antd.Row, null, /*#__PURE__*/_react.default.createElement(_antd.Col, {
    span: 24
  }, /*#__PURE__*/_react.default.createElement(_antd.Row, {
    className: _AuthScreenModule.default.AuthScreen__formContainer__fullsignup
  }, /*#__PURE__*/_react.default.createElement(_antd.Col, {
    className: "signin-options",
    span: 12
  }, props.signup && isDesktopOrLaptop && /*#__PURE__*/_react.default.createElement(_SignupForm.default, props), !props.signup && /*#__PURE__*/_react.default.createElement(_SigninForm.default, props)), (props.signup || isDesktopOrLaptop) && /*#__PURE__*/_react.default.createElement(_antd.Col, {
    className: _AuthScreenModule.default.AuthScreen__formContainer__fullsignup__carousel,
    span: 12
  }, /*#__PURE__*/_react.default.createElement(_Featuredescriptioncarousel.default, props)))))));
};

AuthScreen.propTypes = {
  storeToken: _propTypes.default.func,
  navigate: _propTypes.default.func,
  setUserDetails: _propTypes.default.func,
  realm: _propTypes.default.string,
  clientId: _propTypes.default.string,
  authhandlerUrl: _propTypes.default.string,
  backendUrl: _propTypes.default.string
};
AuthScreen.defaultProps = {
  storeToken: token => {
    sessionStorage.setItem("access_token", token.access_token);
    sessionStorage.setItem("refresh_token", token.refresh_token);
  },
  navigate: to => {
    console.log("navigate to", to);
  },
  setUserDetails: to => {
    console.log("setUserDetails to", to);
  },
  realm: "test-realm-0",
  clientId: "test-realm-client",
  authhandlerUrl: "https://authhandler.dev.hcinbox.smarter.codes",
  backendUrl: "https://backend.dgraph.smarter.codes"
};
var _default = AuthScreen;
exports.default = _default;