const CACHE_NAME = 'xieqa-ai-cache-v2';
const urlsToCache = [
  './index.php',
  './manifest.json',
  './assets/app-icon.svg'
];

self.addEventListener('install', event => {
  event.waitUntil(
    caches.open(CACHE_NAME)
      .then(cache => {
        return cache.addAll(urlsToCache);
      })
  );
});

self.addEventListener('fetch', event => {
  // Hanya gunakan Network First untuk menanggulangi halaman dinamis seperti index.php
  event.respondWith(
    fetch(event.request).catch(() => {
      // Jika jaringan gagal (offline), coba ambil dari cache
      return caches.match(event.request);
    })
  );
});
