/**
 * Service Worker Update Checker
 * Detects when a new build is available and prompts user to reload
 */

if ('serviceWorker' in navigator) {
  // Check for updates every 60 seconds
  setInterval(() => {
    navigator.serviceWorker.getRegistration().then(registration => {
      if (registration) {
        registration.update();
      }
    });
  }, 60000);

  // Listen for service worker updates
  navigator.serviceWorker.addEventListener('controllerchange', () => {
    console.log('[SW] New service worker activated, reloading page...');
    window.location.reload();
  });

  // Force update check on load
  navigator.serviceWorker.ready.then(registration => {
    registration.update();
  });
}
