/* SPDX-License-Identifier: AGPL-3.0-or-later */

import React from "react";

export default (): React.JSX.Element => {
  const [insertIframe, setInsertIframe] = React.useState(false);

  React.useEffect((): (() => void) => {
    const handleIframeLoad = (): (() => void) => {
      // Insert the iframe after a 3000ms delay.
      const timerId = setTimeout((): void => setInsertIframe(true), 3000);

      // Cleanup the timer when the component unmounts.
      return (): void => clearTimeout(timerId);
    };

    window.addEventListener("load", handleIframeLoad);

    window.scroll(0, 0);

    // Cleanup the event listener when the component unmounts.
    return (): void => window.removeEventListener("load", handleIframeLoad);
  }, []); // Empty dependency array means the effect runs only once after initial render.

  return (
    <>
      {/* Use a descriptive title for accessibility */}
      {insertIframe && (
        <iframe
          title="Input Page Preloader"
          src="/input/"
          style={{ display: "none" }}
        />
      )}
    </>
  );
};
