// eslint-disable-next-line no-undef
importScripts(
  "https://storage.googleapis.com/workbox-cdn/releases/4.3.1/workbox-sw.js",
);
/* eslint-disable no-restricted-globals */
/* eslint-disable no-undef */
importScripts("scripts/config.js");

/*  ############    
    TODO: Add MFE service worker ingest.
    to ingest MFE service worker extensions see service-worker-root.js file in openconect-ui for example
    See vlan connect application for example of writing the mfe service worker extension script which can be imported by this worker
   #########

  */

const APP_NAME = "globalportal";
const PRECACHE_CACHE_ID = "precache";
const RUNTIME_CACHE_ID = "runtime";

workbox.setConfig({ debug: false });
workbox.core.clientsClaim();
workbox.core.setCacheNameDetails({
  prefix: APP_NAME,
  suffix: "",
  precache: PRECACHE_CACHE_ID,
  runtime: RUNTIME_CACHE_ID,
});

addEventListener("message", (event) => {
  // Verify source is a client (service workers can only be registered same-origin)
  if (!event.source) {
    return;
  }

  // Validate message structure
  if (!event.data || typeof event.data.type !== 'string') {
    return;
  }
  if (event.data && event.data.type === "SKIP_WAITING") skipWaiting();
});
