"use strict";exports.GraffitiSessionManagerLocal=class{sessionEvents=new EventTarget;constructor(){(async()=>{await Promise.resolve();for(const t of this.getLoggedInActors()){const o=new CustomEvent("login",{detail:{session:{actor:t}}});this.sessionEvents.dispatchEvent(o)}const t=new CustomEvent("initialized");this.sessionEvents.dispatchEvent(t)})()}loggedInActors=[];getLoggedInActors(){if("undefined"!=typeof window){const t=window.localStorage.getItem("graffiti-actor");return t?t.split(",").map(decodeURIComponent):[]}return this.loggedInActors}setLoggedInActors(t){"undefined"!=typeof window?window.localStorage.setItem("graffiti-actor",t.map(encodeURIComponent).join(",")):this.loggedInActors=t}login=async t=>{let o,e=t?.actor;if(!e&&"undefined"!=typeof window){const t=window.prompt("This is an insecure implementation of the Graffiti API for *demo purposes only*. Do not store any sensitive information here. \n\n Simply choose a username to log in.");t&&(e=t)}if(e){const t=this.getLoggedInActors();t.includes(e)||this.setLoggedInActors([...t,e]),o={session:{actor:e}}}else o={error:new Error("No actor ID provided to login")};const n=new CustomEvent("login",{detail:o});this.sessionEvents.dispatchEvent(n)};logout=async t=>{const o=this.getLoggedInActors(),e=o.includes(t.actor);e&&this.setLoggedInActors(o.filter((o=>o!==t.actor)));const n=e?{actor:t.actor}:{actor:t.actor,error:new Error("Not logged in with that actor")},s=new CustomEvent("logout",{detail:n});this.sessionEvents.dispatchEvent(s)}}; //# sourceMappingURL=.cjs.js.map