const CACHE_NAME = 'inventory-v1';
const ASSETS = [
  '/',
  '/css/style.css',
  '/manifest.json',
  '/images/icon-192.png',
  '/images/icon-512.png'
];

// Install event: Cache files
self.addEventListener('install', (e) => {
  e.waitUntil(
    caches.open(CACHE_NAME).then((cache) => cache.addAll(ASSETS))
  );
});

// Fetch event: Serve from cache if available, otherwise fetch from network
self.addEventListener('fetch', (e) => {
  e.respondWith(
    caches.match(e.request).then((response) => {
      return response || fetch(e.request);
    })
  );
});