var p=Object.defineProperty;var S=(a,t,s)=>t in a?p(a,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):a[t]=s;var d=(a,t,s)=>S(a,typeof t!="symbol"?t+"":t,s);class j{constructor(){d(this,"dbName","ClipiveDB");d(this,"recordingsStore","recordings");d(this,"projectsStore","projects");d(this,"version",1);d(this,"db",null)}async open(){return this.db?this.db:new Promise((t,s)=>{const e=indexedDB.open(this.dbName,this.version);e.onupgradeneeded=o=>{const n=o.target.result;n.objectStoreNames.contains(this.recordingsStore)||n.createObjectStore(this.recordingsStore),n.objectStoreNames.contains(this.projectsStore)||n.createObjectStore(this.projectsStore)},e.onsuccess=o=>{this.db=o.target.result,t(this.db)},e.onerror=o=>{s("IndexedDB Open Error: "+o.target.error)}})}async saveBlob(t,s){const e=await this.open();return new Promise((o,n)=>{const r=e.transaction(this.recordingsStore,"readwrite").objectStore(this.recordingsStore);let c;s===null?c=r.delete(t):c=r.put(s,t),c.onsuccess=()=>o(),c.onerror=l=>n(l.target.error)})}async getBlob(t){const s=await this.open();return new Promise((e,o)=>{const r=s.transaction(this.recordingsStore,"readonly").objectStore(this.recordingsStore).get(t);r.onsuccess=()=>e(r.result||null),r.onerror=c=>o(c.target.error)})}async saveProject(t){const s=await this.open();return new Promise((e,o)=>{const r=s.transaction(this.projectsStore,"readwrite").objectStore(this.projectsStore).put(t,t.id);r.onsuccess=()=>e(),r.onerror=c=>o(c.target.error)})}async getProject(t){const s=await this.open();return new Promise((e,o)=>{const r=s.transaction(this.projectsStore,"readonly").objectStore(this.projectsStore).get(t);r.onsuccess=()=>e(r.result||null),r.onerror=c=>o(c.target.error)})}async getAllProjects(){const t=await this.open();return new Promise((s,e)=>{const i=t.transaction(this.projectsStore,"readonly").objectStore(this.projectsStore).getAll();i.onsuccess=()=>s(i.result||[]),i.onerror=r=>e(r.target.error)})}async deleteProject(t){var o,n,i,r,c;const s=await this.open(),e=await this.getProject(t);return e&&e.assets&&((o=e.assets.screen)!=null&&o.key&&await this.saveBlob(e.assets.screen.key,null),(n=e.assets.webcam)!=null&&n.key&&await this.saveBlob(e.assets.webcam.key,null),(i=e.assets.mixedAudio)!=null&&i.key&&await this.saveBlob(e.assets.mixedAudio.key,null),(r=e.assets.micAudio)!=null&&r.key&&await this.saveBlob(e.assets.micAudio.key,null),(c=e.assets.systemAudio)!=null&&c.key&&await this.saveBlob(e.assets.systemAudio.key,null)),new Promise((l,h)=>{const u=s.transaction(this.projectsStore,"readwrite").objectStore(this.projectsStore).delete(t);u.onsuccess=()=>l(),u.onerror=b=>h(b.target.error)})}}const m=new j;export{m as c};
