import React from "react";
import {
Box,
Typography,
Button,
Chip,
Stack,
Paper,
CircularProgress,
} from "@mui/material";
import HFLogo from "../Logo/HFLogo";
import { useAuth } from "../../hooks/useAuth";
import LogoutIcon from "@mui/icons-material/Logout";
import { useNavigate } from "react-router-dom";
import { useTranslation, declareComponentKeys } from "i18n";
function AuthContainer({ actionText = "DO_ACTION" }) {
const { isAuthenticated, user, login, logout, loading } = useAuth();
const navigate = useNavigate();
const {t} = useTranslation({AuthContainer});
const handleLogout = () => {
if (isAuthenticated && logout) {
logout();
navigate("/", { replace: true });
window.location.reload();
}
};
if (loading) {
return (
);
}
if (!isAuthenticated) {
return (
{t("login")}
{t("need")}
);
}
return (
{t("loggedin", {user: (user !== null ? user!['username'] : "inconnu")})}
}
color="primary"
sx={{
minWidth: 120,
height: 36,
textTransform: "none",
fontSize: "0.9375rem",
}}
>
{t("logout")}
);
}
const { i18n } = declareComponentKeys<
| "login"
| "need"
| "logout"
| "button"
| { K: "loggedin"; P: { user: string; }; R: JSX.Element }
>()({ AuthContainer });
export type I18n = typeof i18n;
export default AuthContainer;