import{a9 as u,a6 as h,s as l}from"./jwt-decode.esm-CQm3LY6y.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]="de086f20-000f-4bdc-98f6-54a80230bbad",a._sentryDebugIdIdentifier="sentry-dbid-de086f20-000f-4bdc-98f6-54a80230bbad")}catch{}})();class d{topics;subUid;constructor(){this.topics={},this.subUid=-1}subscribe(t,s){const i=(++this.subUid).toString();return this.topics[t]||(this.topics[t]=[]),this.topics[t].push({token:i,func:s}),i}async wait(t){return new Promise(s=>{const i=this.subscribe(t,e=>{this.unsubscribe(i),s(e)})})}async publish(t,...s){if(!this.topics[t])return!1;const i=this.topics[t];let e=i?i.length:0;for(;e--;)await i[e].func(s[0]);return!0}unsubscribe(t){for(const s in this.topics)if(this.topics[s]){for(let i=0,e=this.topics[s].length;i<e;i++)if(this.topics[s][i].token===t)return this.topics[s].splice(i,1),t}return!1}reset(){this.topics={},this.subUid=-1}}class n{initialState;pubsub;_changes;constructor(t){this.initialState=t,this.pubsub=new d,this._changes=l({})}static from(t){return h(new n(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:Object.keys(this.changes).length>0}hasChangesDeep(t){return t in this.changes&&!u.isEqual(this.initialState[t],this.changes[t])}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 c extends n{api;constructor(t,s){super(s),this.api=t}static create(t,s){return h(new c(t,s))}getInitialState(t){return this.initialState[t]}updateInitialState(t,s){this.initialState[t]=s,delete this._changes.value[t]}async save(t){if(Object.keys(this.changes).length===0||t&&!(t in this.changes))return;if(t){const i={[t]:this.changes[t]},e=await this.api.update(this.initialState.id,i);this.initialState={...this.initialState,...e},delete this._changes.value[t];return}this.initialState=await this.api.update(this.initialState.id,this.changes);const s={...this.changes};this._changes.value={},this.pubsub.publish("update",s)}}class r extends n{api;debouncedSave;constructor(t,s){super(s),this.api=t,this.debouncedSave=u.debounce(()=>{this.save()},500)}static create(t,s){return h(new r(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(Object.keys(this.changes).length===0||t&&!(t in this.changes))return;if(t){const i={[t]:this.changes[t]},e=await this.api.update(this.initialState.id,i);this.initialState={...this.initialState,...e},delete this._changes.value[t];return}this.initialState=await this.api.update(this.initialState.id,this.changes);const s={...this.changes};this._changes.value={},this.pubsub.publish("update",s)}}export{c as A,n as E,d as P,r as a};
//# sourceMappingURL=record-Dzon-Vi8.js.map
