import usePostGetTotem from "@/query/usePostGetTotem";
import CryptoJS from "crypto-js";
import { useCallback } from "react";

export default function useAutoLogIn() {
  const { mutateAsync: postGetTotem } = usePostGetTotem();

  return useCallback(async () => {
    if (window.localStorage.getItem("autoLogIn") === "true") {
      await postGetTotem({
        avatarID: window.localStorage.getItem("avatarID") ?? "",
        avatarCipher: CryptoJS.AES.decrypt(
          window.localStorage.getItem("avatarCipher") ?? "",
          "591A6F91-2A27-4A88-88FA-0FEB7CB5FD94",
        ).toString(CryptoJS.enc.Utf8),
      });
    }
  }, [postGetTotem]);
}
