(()=>{"use strict";console.log("WORKER"),self.__WB_MANIFEST,self.addEventListener("push",(function(t){console.log("data",t.data.text());const{message:n,callId:i,createdAt:s,visitor:r,dst:c}=JSON.parse(t.data.text()),a=o().then((t=>function(t,o){return new Promise(((n,i)=>{const s=t.transaction([e],"readwrite").objectStore(e).put(o);s.onerror=t=>i(t.target.errorCode),s.onsuccess=t=>n(t.target.result)}))}(t,{callId:i,createdAt:s,visitor:r,dst:c}))),l=registration.showNotification(n,{body:"30秒以内に回答してください",icon:"/icons/android-chrome-192x192.png",data:JSON.stringify({callId:i,createdAt:s,visitor:r,dst:c}),actions:[{action:"accept",title:"対応可能"},{action:"reject",title:"対応不可"}]});t.waitUntil(Promise.all([a,l]).catch((t=>{console.error("Error in one of the push event processes:",t)})))})),self.addEventListener("notificationclick",(function(t){var e;console.log("notificationclick");const o=null==t||null===(e=t.notification)||void 0===e?void 0:e.data;t.notification.close(),t.waitUntil(clients.matchAll({type:"window",includeUncontrolled:!0,userVisibleOnly:!0}).then((function(e){let n=`/actions?data=${encodeURIComponent(o)}&action=${t.action}`;for(let t=0;t<e.length;t++){let o=e[t];if("url"in o&&o.url.includes(n)&&"focus"in o)return o.navigate(n),o.focus()}clients.openWindow&&clients.openWindow(n)})))})),self.addEventListener("install",(function(t){console.log("install"),self.skipWaiting()})),self.addEventListener("activate",(function(t){console.log("activate"),clients.claim()})),self.addEventListener("pushsubscriptionchange",(function(t){console.log("pushsubscriptionchange"),t.waitUntil(Promise.all([Promise.resolve(!t.oldSubscription||i(t.oldSubscription)),Promise.resolve(t.newSubscription?t.newSubscription:n(registration)).then((function(t){return saveSubscription(t)}))]))}));const t="pwa-db",e="subscriptions";function o(){return new Promise(((o,n)=>{const i=indexedDB.open(t,1);i.onupgradeneeded=t=>{t.target.result.createObjectStore(e,{keyPath:"id"})},i.onerror=t=>n(t.target.errorCode),i.onsuccess=t=>o(t.target.result)}))}async function n(t){try{console.log(t);const e=await fetch("/api/mobile",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({registration:t})});if(!e.ok)throw new Error("Failed to subscribe to push service.");const n=await e.json(),i=await o();await storeIdentifier(i,n.identifier),console.log("Identifier stored in IndexedDB:",n.identifier)}catch(t){console.error("Error in subscribePush:",t)}}async function i(t){console.log(t);if(!(await fetch("/api/mobile",{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({oldSubscription:t})})).ok)throw new Error("Failed to subscribe to push service.")}})();