import { useEffect, useState } from "react";

export function useLastLoginedAccount() : [
    string,
    (publicKey: string) => void
] {
    const [lastLoginedAccount, setLastLogginedAccount] = 
        useState<string>("");

    useEffect(() => {
        let publicKey = 
            localStorage.getItem("last_logined_account");
        if(!publicKey){
            return;
        }
        setLastLogginedAccount(publicKey);
    }, []);

    const setLastLogin = (publicKey: string) => {
        localStorage.setItem("last_logined_account", publicKey);
        setLastLogginedAccount(publicKey);
    }

    return [lastLoginedAccount, setLastLogin];
}