(globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["object"==typeof document?document.currentScript:void 0,17449,e=>{"use strict";let t="images";async function r(){return new Promise((e,r)=>{let o=indexedDB.open("CharacterImagesDB",1);o.onerror=()=>{r(Error(`IndexedDB error: ${o.error}`))},o.onsuccess=()=>{e(o.result)},o.onupgradeneeded=e=>{let r=e.target.result;if(!r.objectStoreNames.contains(t)){let e=r.createObjectStore(t,{keyPath:"id"});e.createIndex("timestamp","timestamp",{unique:!1}),e.createIndex("type","metadata.type",{unique:!1})}}})}async function o(e,o,a,n){let s=await r();return new Promise((r,i)=>{let l=s.transaction([t],"readwrite").objectStore(t),c={id:e,blob:o,sourceUrl:a,timestamp:Date.now(),metadata:n},u=l.put(c);u.onsuccess=()=>{s.close(),r()},u.onerror=()=>{s.close(),i(Error(`Failed to save image: ${u.error}`))}})}async function a(e){let o=await r();return new Promise((r,a)=>{let n=o.transaction([t],"readonly").objectStore(t).get(e);n.onsuccess=()=>{o.close();let e=n.result;r(e?e.blob:null)},n.onerror=()=>{o.close(),a(Error(`Failed to get image: ${n.error}`))}})}async function n(e){let o=await r();return new Promise((r,a)=>{let n=o.transaction([t],"readonly").objectStore(t).get(e);n.onsuccess=()=>{o.close(),r(n.result||null)},n.onerror=()=>{o.close(),a(Error(`Failed to get image record: ${n.error}`))}})}async function s(e){let o=await r();return new Promise((r,a)=>{let n=o.transaction([t],"readwrite").objectStore(t).delete(e);n.onsuccess=()=>{o.close(),r()},n.onerror=()=>{o.close(),a(Error(`Failed to delete image: ${n.error}`))}})}async function i(){let e=await r();return new Promise((r,o)=>{let a=e.transaction([t],"readonly").objectStore(t).getAll();a.onsuccess=()=>{e.close(),r(a.result||[])},a.onerror=()=>{e.close(),o(Error(`Failed to get all images: ${a.error}`))}})}async function l(e=2592e6){let o=await r(),a=Date.now()-e;return new Promise((e,r)=>{let n=o.transaction([t],"readwrite").objectStore(t).index("timestamp"),s=IDBKeyRange.upperBound(a),i=n.openCursor(s),l=0;i.onsuccess=t=>{let r=t.target.result;r?(r.delete(),l++,r.continue()):(o.close(),e(l))},i.onerror=()=>{o.close(),r(Error(`Failed to clear old images: ${i.error}`))}})}async function c(e){try{let t=await a(e);return null!==t}catch(e){return console.error("Error checking image existence:",e),!1}}async function u(){if("estimate"in navigator.storage){let e=await navigator.storage.estimate();return{usage:e.usage||0,quota:e.quota||0}}return null}async function m(e,t=3e4){let r=new AbortController,o=setTimeout(()=>r.abort(),t);try{let t=await fetch(e,{signal:r.signal});return clearTimeout(o),t}catch(e){throw clearTimeout(o),e}}async function g(e,t,r,a=3){let n;for(let s=1;s<=a;s++)try{let a=3e4+(s-1)*15e3,n=await m(t,a);if(!n.ok){if(524===n.status||n.status>=500)throw Error(`Server error (${n.status} ${n.statusText})`);throw Error(`Failed to fetch image (${n.status} ${n.statusText}): ${t}`)}let i=await n.blob();await o(e,i,t,r);return}catch(r){n=r;let t="AbortError"===r.name||r.message.includes("524")||r.message.includes("Server error")||r.message.includes("Network");if(s<a&&t){let t=1e3*Math.pow(2,s);console.warn(`Attempt ${s} failed for ${e}. Retrying image download in ${t}ms...`,r.message),await new Promise(e=>setTimeout(e,t))}else break}throw console.warn(`Final error downloading and saving image to IndexedDB for ${e}:`,n),n}function d(){return Math.floor(13*Math.random())+1}function w(){let e=d();return`/media/avatar${e}.png`}e.s(["clearOldImages",()=>l,"deleteImage",()=>s,"downloadAndSaveImage",()=>g,"getAllImages",()=>i,"getImage",()=>a,"getImageRecord",()=>n,"getRandomAvatarNumber",()=>d,"getRandomDefaultAvatar",()=>w,"getStorageInfo",()=>u,"imageExists",()=>c,"initDB",()=>r,"saveImage",()=>o])}]);