import{c as t,f as a,g as i,a as n,b as c,d,i as o}from"./p-d2c730d4.js";export{j as deleteAuth,k as deleteUser,g as getIdentity,e as initAuth,h as signIn,s as signOut,u as updateUser}from"./p-d2c730d4.js";import"./p-5b224066.js";const r=({IDL:t})=>{const e=t.Text,a=t.Principal;return t.Service({del:t.Func([e],[t.Bool],[]),deleteDecksAdmin:t.Func([t.Principal],[],[]),entries:t.Func([],[t.Vec(a)],["query"]),get:t.Func([e],[t.Opt(a)],["query"]),init:t.Func([e],[a],[])})},y=({IDL:t})=>{const e=t.Text,a=t.Int,i=t.Text,n=t.Record({updated_at:a,data:t.Vec(t.Nat8),deckId:i,created_at:a}),s=t.Text,c=t.Record({updated_at:a,data:t.Vec(t.Nat8),created_at:a,slideId:s});return t.Service({delSlide:t.Func([e],[t.Bool],[]),get:t.Func([],[n],["query"]),getSlide:t.Func([e],[c],["query"]),set:t.Func([n],[],[]),setSlide:t.Func([c],[],[]),transferCycles:t.Func([],[],[])})},l=({identity:e,host:a})=>t({canisterId:process.env.MANAGER_CANISTER_ID,idlFactory:r,identity:e,host:a}),w=({identity:e,bucket:a,host:i})=>t({canisterId:a,idlFactory:y,identity:e,host:i}),p=async()=>{const t=i();if(!t)return[];const e=await l({identity:t});console.log("Deck IC about to request entries");const a=await e.entries();console.log("Deck IC entries done.",a);const n=a.map((e=>I({bucket:e,identity:t}))),s=await Promise.all(n);console.log("Deck IC decks done.",s);const c=null==s?void 0:s.filter((t=>void 0!==t)).map((e=>b({deck:e,identity:t})));return await Promise.all(c)},I=async({bucket:t,identity:e})=>{try{const a=await w({identity:e,bucket:t});return await a.get()}catch(e){return void console.error("Deck cannot be found.",t)}},b=async({deck:t,identity:e})=>{const a=await c(t.data);return{id:t.deckId,data:Object.assign(Object.assign({},a),{owner_id:e.getPrincipal().toText(),created_at:n(t.created_at),updated_at:n(t.updated_at)})}},f=async t=>{if(!t)return;const e=i();if(!e)return;const a=await l({identity:e});console.log("Deck IC about to delete deck and its slides"),await a.del(t),console.log("Deck IC delete")},m=(t,e)=>new Promise((async(s,d)=>{const o=i();if(o)try{const i=await l({identity:o}),d=await(async({managerActor:t,deckId:e})=>a(await t.get(e))||await t.init(e))({managerActor:i,deckId:t}),r=await w({identity:o,bucket:d}),y=await r.getSlide(e),u=await c(y.data);s({id:e,data:Object.assign(Object.assign({},u),{created_at:n(y.created_at),updated_at:n(y.updated_at)})})}catch(t){d(t)}else d("No internet identity.")})),D=async()=>{},_=async()=>null,C=async()=>{},q=d(import("./p-b3f709fa.js").then((t=>t.worker)),"stencil.sync.ic.worker","uploadWorker"),A=async({syncData:t,clean:e})=>{if(!i())throw new Error("No internet identity to sync data");const a=await o();await q({internetIdentity:a,syncData:t,host:`${window.location}`}),await e(t)};export{p as deckEntries,f as deleteDeck,_ as getFiles,C as getFolders,m as getSlide,A as sync,D as uploadFile}