const CACHE = "anime-character-maker-mobile-v5";
const ASSETS = [
  "./",
  "index.html",
  "styles.css",
  "catalog-data.js?v=20260513d",
  "app.js?v=20260513d",
  "manifest.webmanifest",
  "../assets/app_icon.png",
  "../assets/selector_icons/skin.png",
  "../assets/selector_icons/species.png",
  "../assets/selector_icons/eye.png",
  "../assets/selector_icons/hair_color.png",
  "../assets/selector_icons/hair_style.png",
  "../assets/selector_icons/outfit.png",
  "../assets/selector_icons/top.png",
  "../assets/selector_icons/bottom.png",
  "../assets/selector_icons/socks.png",
  "../assets/selector_icons/shoes.png",
  "../assets/selector_icons/gloves.png",
  "../assets/selector_icons/hat.png",
  "../assets/selector_icons/accessory.png",
  "../assets/selector_icons/background.png",
];

self.addEventListener("install", (event) => {
  event.waitUntil(caches.open(CACHE).then((cache) => cache.addAll(ASSETS)));
});

self.addEventListener("activate", (event) => {
  event.waitUntil(
    caches
      .keys()
      .then((keys) => Promise.all(keys.filter((key) => key !== CACHE).map((key) => caches.delete(key))))
  );
});

self.addEventListener("fetch", (event) => {
  event.respondWith(caches.match(event.request).then((cached) => cached || fetch(event.request)));
});
