/**
 * Minimal service worker — exists so the PWA is installable.
 * Network-only fetch: always hit the origin for live files.
 * No cache-first, no precache (script/CSS cache-busting uses config.js ?v=).
 */
const SW_VERSION = "ccs-pdf-editor-sw-network-only-v1";

self.addEventListener("install", (event) => {
    // Activate immediately on first install / update
    event.waitUntil(self.skipWaiting());
});

self.addEventListener("activate", (event) => {
    event.waitUntil(
        (async () => {
            // Drop any accidental old caches from prior network-then-cache SW
            const keys = await caches.keys();
            await Promise.all(keys.map((k) => caches.delete(k)));
            await self.clients.claim();
            console.log("[sw]", SW_VERSION, "active (network-only)");
        })()
    );
});

// Pure pass-through — browser hits the origin directly (no Cache API).
// Required for some installability checks; must not cache responses.
self.addEventListener("fetch", (event) => {
    event.respondWith(fetch(event.request));
});
