import{_}from"./index-CuYiwiAV.js";function g(p={}){const{immediate:u=!1,onNeedRefresh:n,onOfflineReady:i,onRegistered:o,onRegisteredSW:c,onRegisterError:r}=p;let e,d,s;const w=async(t=!0)=>{await d,await(s==null?void 0:s())};async function m(){if("serviceWorker"in navigator){if(e=await _(async()=>{const{Workbox:t}=await import("./workbox-window.prod.es5-D5gOYdM7.js");return{Workbox:t}},[],import.meta.url).then(({Workbox:t})=>new t("./sw.js",{scope:"./",type:"classic"})).catch(t=>{r==null||r(t)}),!e)return;s=async()=>{await(e==null?void 0:e.messageSkipWaiting())};{let t=!1;const l=()=>{t=!0,e==null||e.addEventListener("controlling",a=>{a.isUpdate&&window.location.reload()}),n==null||n()};e.addEventListener("installed",a=>{typeof a.isUpdate>"u"?typeof a.isExternal<"u"?a.isExternal?l():!t&&(i==null||i()):a.isExternal?window.location.reload():!t&&(i==null||i()):a.isUpdate||i==null||i()}),e.addEventListener("waiting",l),e.addEventListener("externalwaiting",l)}e.register({immediate:u}).then(t=>{c?c("./sw.js",t):o==null||o(t)}).catch(t=>{r==null||r(t)})}}return d=m(),w}export{g as registerSW};
