const CACHE_NAME = 'trinity-console-v1';
const STATIC_ASSETS = [
  '/css/app.css',
  '/manifest.json'
];

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

self.addEventListener('fetch', event => {
  // Only cache GET requests for static assets
  if (event.request.method !== 'GET') return;
  if (event.request.url.includes('/admin/')) return; // Never cache admin routes

  event.respondWith(
    caches.match(event.request).then(cached => cached || fetch(event.request))
  );
});
