"use strict";

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

var _auth0React = require("@auth0/auth0-react");

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

var _constants = require("../../util/constants");

var _ui = require("../../util/ui");

var _navLoginButton = _interopRequireDefault(require("./nav-login-button"));

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

/**
 * This component wraps NavLoginButton with Auth0 information.
 */
const NavLoginButtonAuth0 = ({
  className,
  id,
  links,
  style
}) => {
  const {
    isAuthenticated,
    loginWithRedirect,
    logout,
    user
  } = (0, _auth0React.useAuth0)(); // On login, preserve the current trip query if any.

  const handleLogin = () => loginWithRedirect({
    appState: {
      returnTo: (0, _ui.getCurrentRoute)()
    }
  });

  const handleLogout = () => logout({
    // Logout to the map with no search.
    returnTo: _constants.URL_ROOT
  }); // On logout, it is better to "clear" the screen, so
  // return to redirectUri set in <Auth0Provider> (no specific event handler).


  return /*#__PURE__*/_react.default.createElement(_navLoginButton.default, {
    className: className,
    id: id,
    links: links,
    onSignInClick: handleLogin,
    onSignOutClick: handleLogout,
    profile: isAuthenticated ? user : null,
    style: style
  });
};

var _default = NavLoginButtonAuth0;
exports.default = _default;
module.exports = exports.default;

//# sourceMappingURL=nav-login-button-auth0.js