const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./DhbIUrRN.js","./B19SJqt6.js","./entry.Cpx2R9of.css"])))=>i.map(i=>d[i]); import{bO as w,ba as b,bP as d,bQ as u,bR as g}from"./B19SJqt6.js";async function p(n,o="gzip"){const e=Uint8Array.from(atob(n),s=>s.charCodeAt(0)),r=new Response(new Blob([e])).body?.pipeThrough(new DecompressionStream(o)),c=await new Response(r).text();return JSON.parse(c)}function l(n,o){const e=S(n),t={...o};for(const r in t)e[r]==="json"&&t[r]&&t[r]!=="undefined"&&(t[r]=JSON.parse(t[r])),e[r]==="boolean"&&t[r]!=="undefined"&&(t[r]=!!t[r]);for(const r in t)t[r]==="NULL"&&(t[r]=void 0);return t}function S(n){const o=n.match(/FROM\s+(\w+)/);return o?w[h(o[1])]?.fields||{}:{}}function h(n){return n.replace(/^_content_/,"")}let a;const f={},i={};function D(n){async function o(e){return a||(i._=i._||_(),a=await i._,Reflect.deleteProperty(i,"_")),f[String(e)]||(i[String(e)]=i[String(e)]||y(e),await i[String(e)],f[String(e)]="loaded",Reflect.deleteProperty(i,String(e))),a}return{all:async(e,t)=>(await o(n),a.exec({sql:e,bind:t,rowMode:"object",returnValue:"resultRows"}).map(r=>l(e,r))),first:async(e,t)=>(await o(n),l(e,a.exec({sql:e,bind:t,rowMode:"object",returnValue:"resultRows"}).shift())),exec:async(e,t)=>{await o(n),await a.exec({sql:e,bind:t})}}}async function _(){if(!a){const n=await b(()=>import("./DhbIUrRN.js"),__vite__mapDeps([0,1,2]),import.meta.url).then(e=>e.default);globalThis.sqlite3ApiConfig={silent:!0,debug:(...e)=>console.debug(...e),warn:(...e)=>{String(e[0]).includes("OPFS sqlite3_vfs")||console.warn(...e)},error:(...e)=>console.error(...e),log:(...e)=>console.log(...e)};const o=await n();a=new o.oo1.DB}return a}async function y(n){if(window.sessionStorage.getItem("previewToken"))return a;let o=null;const e=`checksum_${n}`,t=`collection_${n}`;let r="matched";try{a.exec({sql:`SELECT * FROM ${d.info} where id = '${e}'`,rowMode:"object",returnValue:"resultRows"}).shift()?.version!==u[String(n)]&&(r="mismatch")}catch{r="missing"}if(r!=="matched"){if(window.localStorage.getItem(`content_${e}`)===u[String(n)]&&(o=window.localStorage.getItem(`content_${t}`)),!o){o=await g(void 0,String(n));try{window.localStorage.setItem(`content_${e}`,u[String(n)]),window.localStorage.setItem(`content_${t}`,o)}catch(s){console.error("Database integrity check failed, rebuilding database",s)}}const c=await p(o);await a.exec({sql:`DROP TABLE IF EXISTS ${d[String(n)]}`}),r==="mismatch"&&await a.exec({sql:`DELETE FROM ${d.info} WHERE id = '${e}'`});for(const s of c)try{await a.exec(s)}catch(m){console.error("Error executing command",m)}}return a}export{D as loadDatabaseAdapter};