import React, { useMemo, useCallback } from "react";
import PropTypes from "prop-types";
import { useSelector } from "react-redux";
import useTranslation from "../../utils/useTranslation";
import { ReactComponent as SBBUser } from "../../img/sbb/user_92_large.svg";
import "./Login.scss";
function Login(_ref) {
  let {
    loginUrl
  } = _ref;
  const {
    t
  } = useTranslation();
  const appBaseUrl = useSelector(state => state.app.appBaseUrl);
  const language = useSelector(state => state.app.language);
  const permissionInfos = useSelector(state => state.app.permissionInfos);
  const login = useMemo(() => {
    if (permissionInfos && permissionInfos.user) {
      return permissionInfos.user;
    }
    return t("Anmelden");
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [permissionInfos, language]);
  const openLoginPage = useCallback(() => {
    window.location.href = loginUrl || "".concat(appBaseUrl, "/login?next=").concat(encodeURIComponent(window.location.href));
  }, [appBaseUrl, loginUrl]);
  return /*#__PURE__*/React.createElement("div", {
    className: "wkp-login",
    role: "button",
    onClick: openLoginPage,
    onKeyPress: evt => evt.which === 13 && openLoginPage(),
    tabIndex: 0,
    title: permissionInfos && permissionInfos.user
  }, /*#__PURE__*/React.createElement(SBBUser, {
    focusable: false,
    className: "wkp-login-icon"
  }), /*#__PURE__*/React.createElement("span", {
    className: "wkp-login-text"
  }, login));
}
Login.propTypes = {
  loginUrl: PropTypes.string
};
export default /*#__PURE__*/React.memo(Login);
//# sourceMappingURL=Login.js.map