// Logout.tsx
import React from "react";
import { useNavigate } from "react-router-dom";
import { toast } from "sonner";
import LogoutModal from "../Modals/LogoutModal/LogoutModal";

interface LogoutProps {
	setLogoutModal: React.Dispatch<React.SetStateAction<boolean>>;
	logoutModal: boolean;
}

const Logout: React.FC<LogoutProps> = ({ setLogoutModal, logoutModal }) => {
	const navigate = useNavigate();

	const handlelogout = () => {
		localStorage.clear();
		navigate("/login");
		toast.success("Logged out successfully");
		setLogoutModal(false);
	};

	return (
		<>
			{logoutModal && (
				<LogoutModal
					handlelogout={handlelogout}
					open={logoutModal}
					setLogoutModal={setLogoutModal}
				/>
			)}
		</>
	);
};

export default Logout;
