// Poll the server to check if processing is complete
// This runs on the loading page and waits for the backend to finish

let checkInterval = setInterval(() => {
  fetch("/check_status")
    .then(response => response.json())
    .then(data => {
      if (data.status === "complete") {
        // Processing is complete, redirect to results
        clearInterval(checkInterval);
        window.location.href = "/results";
      }
      // Otherwise keep polling
    })
    .catch(error => {
      console.log("Still processing...", error);
    });
}, 2000); // Check every 2 seconds