import { useEffect, useState } from "react";
import { AuthContextProps } from "./auth";
import { EasterEgg, getEasterEgg } from "../../../types";

export const useEasterEgg = (auth?: AuthContextProps | null): [EasterEgg | undefined, boolean] => {
  const [result, setResult] = useState<EasterEgg | undefined>();
  const [loading, setLoading] = useState(false);

  useEffect(() => {
    async function fetchEasterEgg() {
      if (auth?.login) {
        setLoading(true);
        const egg = (await getEasterEgg())?.data;
        setResult(egg);
        setLoading(false);
      }
    }
    fetchEasterEgg();

  }, [auth?.login]);

  return [result, loading];
}
