import { FrontendVariables } from "@Front/Config/VariablesFront";
import UserStore from "@Front/Stores/UserStore";
import { PowerIcon } from "@heroicons/react/24/outline";
import { useRouter } from "next/router";
import React, { useCallback } from "react";

import MenuItem from "../Menu/MenuItem";

export default function LogOut() {
	const router = useRouter();
	const variables = FrontendVariables.getInstance();

	const disconnect = useCallback(() => {
		UserStore.instance
			.disconnect()
			.then(() => router.push(`https://qual-connexion.idnot.fr/user/auth/logout?sourceURL=${variables.FRONT_APP_HOST}`));
	}, [router, variables.FRONT_APP_HOST]);

	return <MenuItem item={{ text: "Déconnexion", icon: <PowerIcon />, onClick: disconnect }} />;
}
