import{a9 as n,a6 as r,s as d}from"./jwt-decode.esm-DyyavT6h.js";(function(){try{var a=typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},t=new Error().stack;t&&(a._sentryDebugIds=a._sentryDebugIds||{},a._sentryDebugIds[t]="f5355e91-28c9-4857-a10f-7dfc0052b02d",a._sentryDebugIdIdentifier="sentry-dbid-f5355e91-28c9-4857-a10f-7dfc0052b02d")}catch{}})();class p{topics;subUid;constructor(){this.topics={},this.subUid=-1}subscribe(t,s){const e=(++this.subUid).toString();return this.topics[t]||(this.topics[t]=[]),this.topics[t].push({token:e,func:s}),e}async wait(t){return new Promise(s=>{const e=this.subscribe(t,i=>{this.unsubscribe(e),s(i)})})}async publish(t,...s){if(!this.topics[t])return!1;const e=this.topics[t];let i=e?e.length:0;for(;i--;)await e[i].func(s[0]);return!0}unsubscribe(t){for(const s in this.topics)if(this.topics[s]){for(let e=0,i=this.topics[s].length;e<i;e++)if(this.topics[s][e].token===t)return this.topics[s].splice(e,1),t}return!1}reset(){this.topics={},this.subUid=-1}}class h{initialState;pubsub;_changes;constructor(t){this.initialState=t,this.pubsub=new p,this._changes=d({})}static from(t){return r(new h(t))}get changes(){return this._changes.value}get(t){return this.changes[t]??this.initialState[t]}set(t,s){this._changes.value={...this.changes,[t]:s}}hasChanges(t){return t?t in this.changes&&!n.isEqual(this.initialState[t],this.changes[t]):Object.keys(this.changes).some(s=>!n.isEqual(this.initialState[s],this.changes[s]))}get state(){return{...this.initialState,...this.changes}}resetChanges(){const t={...this.changes};this._changes.value={},this.pubsub.publish("update",t)}onUpdate(t){this.pubsub.subscribe("update",t)}commit(){this.initialState=this.state,this._changes.value={}}toDTO(){return{...this.state,...this._changes.value}}update(t){this._changes.value={...this.changes,...t}}}class o extends h{api;constructor(t,s){super(s),this.api=t}static create(t,s){return r(new o(t,s))}getInitialState(t){return this.initialState[t]}updateInitialState(t,s){this.initialState[t]=s,delete this._changes.value[t]}async save(t){if(!this.hasChanges(t??void 0))return;if(t){const i=this.changes[t],c={[t]:i},u=await this.api.update(this.initialState.id,c);this.initialState={...this.initialState,...u};return}const s={};for(const i of Object.keys(this.changes))n.isEqual(this.initialState[i],this.changes[i])||(s[i]=this.changes[i]);if(Object.keys(s).length===0)return;const e=await this.api.update(this.initialState.id,s);for(const i of Object.keys(s))i in e&&(this.initialState[i]=e[i]);this.pubsub.publish("update",s)}}class l extends h{api;debouncedSave;constructor(t,s){super(s),this.api=t,this.debouncedSave=n.debounce(()=>{this.save()},500)}static create(t,s){return r(new l(t,s))}getInitialState(t){return this.initialState[t]}updateInitialState(t,s){this.initialState[t]=s,delete this._changes.value[t]}set(t,s){super.set(t,s),this.debouncedSave()}async save(t){if(!this.hasChanges(t??void 0))return;if(t){const i=this.changes[t],c={[t]:i},u=await this.api.update(this.initialState.id,c);this.initialState={...this.initialState,...u};return}const s={};for(const i of Object.keys(this.changes))n.isEqual(this.initialState[i],this.changes[i])||(s[i]=this.changes[i]);if(Object.keys(s).length===0)return;const e=await this.api.update(this.initialState.id,s);for(const i of Object.keys(s))i in e&&(this.initialState[i]=e[i]);this.pubsub.publish("update",s)}}export{o as A,h as E,p as P,l as a};
//# sourceMappingURL=record-Dva_8M1P.js.map
