import { useEffect, useState } from "react";

const PRELOAD_URL = "/lsf/lsf.html";

export default function LabelStudioPreloader() {
  const [shouldLoad, setShouldLoad] = useState(false);

  useEffect(() => {
    // Delay preloading slightly to avoid contending with initial page load resources
    // Using 2000ms (2 seconds) as a reasonable idle time approximation
    const timer = setTimeout(() => {
      setShouldLoad(true);
    }, 2000);

    return () => clearTimeout(timer);
  }, []);

  if (!shouldLoad) return null;

  return (
    <iframe
      src={PRELOAD_URL}
      style={{
        display: "none",
        width: 0,
        height: 0,
        border: 0,
        position: "absolute",
        visibility: "hidden"
      }}
      title="Label Studio Preloader"
      aria-hidden="true"
    />
  );
}
