const CACHE = "tahta-pwa-v1";
const ASSETS = ["/tahta/controller.php", "/tahta/login.php", "/tahta/board.php", "/tahta/pwa/manifest.json"];

self.addEventListener("install", (e) => {
  e.waitUntil(caches.open(CACHE).then((c)=>c.addAll(ASSETS)));
});
self.addEventListener("activate", (e) => e.waitUntil(self.clients.claim()));
self.addEventListener("fetch", (e) => {
  const req = e.request;
  if (req.mode === "navigate") {
    e.respondWith(caches.match("/tahta/controller.php").then((c)=> c || fetch(req)));
    return;
  }
  e.respondWith(caches.match(req).then((c)=> c || fetch(req)));
});
