import { useEffect, useState } from "react";

export function useAutoOpenTimer(autoOpenTime: number) {
  const [isWidgetHidden, setIsWidgetHidden] = useState<boolean>(autoOpenTime ? true : false);

  useEffect(
    function setAutoOpenTimer() {
      if (!autoOpenTime) return;

      const timeout = setTimeout(() => setIsWidgetHidden(false), autoOpenTime * 1000);

      return () => {
        clearTimeout(timeout);
      };
    },
    [autoOpenTime]
  );

  return isWidgetHidden;
}
