import CryptoJS from "crypto-js";

import usePostGetTotem from "src/avatar/usePostGetTotem";

export default function useAutoSignIn() {
  const { mutate: postGetTotem } = usePostGetTotem();

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