// RGSP service worker — SELF-DESTRUCT build.
//
// The previous SW cached the app shell and served stale HTML that
// survived hard-refresh / incognito / different machines, masking
// deploys. We have removed SW registration from the app. This file
// remains only so that any browser that STILL has an old SW registered
// will, when it re-fetches /sw.js, install this version which
// immediately unregisters itself and deletes all caches — healing the
// client without any manual "clear site data" step.

self.addEventListener("install", () => {
  self.skipWaiting();
});

self.addEventListener("activate", (event) => {
  event.waitUntil(
    (async () => {
      // Wipe every cache this origin holds.
      const keys = await caches.keys();
      await Promise.all(keys.map((k) => caches.delete(k)));
      // Unregister self so future loads talk straight to the network.
      await self.registration.unregister();
      // Force all open tabs to reload from the network now.
      const clients = await self.clients.matchAll({ type: "window" });
      clients.forEach((c) => c.navigate(c.url));
    })()
  );
});

// Never intercept anything — pure passthrough to the network.
self.addEventListener("fetch", () => {});
