// Service Worker simples para permitir a instalação do APP BRT Express
self.addEventListener('fetch', function(event) {
    // Mantém o app funcionando online
});
const cacheName = 'brt-express-v1';
const staticAssets = [
  './',
  '.cadastro.php',
  '.manifest2.json',
  '.logo-192.png',
  '.logo-512.png'
];

self.addEventListener('install', async event => {
  const cache = await caches.open(cacheName);
  await cache.addAll(staticAssets);
});

self.addEventListener('fetch', event => {
  const req = event.request;
  event.respondWith(cacheFirst(req));
});

async function cacheFirst(req) {
  const cache = await caches.open(cacheName);
  const cached = await cache.match(req);
  return cached || fetch(req);
}