var o=Object.defineProperty;var d=(i,s,t)=>s in i?o(i,s,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[s]=t;var n=(i,s,t)=>(d(i,typeof s!="symbol"?s+"":s,t),t);import{N as b,eE as c,ej as r}from"./jwt-decode.esm.d4517a10.js";(function(){try{var i=typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},s=new Error().stack;s&&(i._sentryDebugIds=i._sentryDebugIds||{},i._sentryDebugIds[s]="7d85dab9-e950-4244-9f4f-274ebbe42be1",i._sentryDebugIdIdentifier="sentry-dbid-7d85dab9-e950-4244-9f4f-274ebbe42be1")}catch{}})();class p{constructor(){n(this,"topics");n(this,"subUid");this.topics={},this.subUid=-1}subscribe(s,t){const e=(++this.subUid).toString();return this.topics[s]||(this.topics[s]=[]),this.topics[s].push({token:e,func:t}),e}async wait(s){return new Promise(t=>{const e=this.subscribe(s,a=>{this.unsubscribe(e),t(a)})})}async publish(s,...t){if(!this.topics[s])return!1;const e=this.topics[s];let a=e?e.length:0;for(;a--;)await e[a].func(t[0]);return!0}unsubscribe(s){for(const t in this.topics)if(this.topics[t]){for(let e=0,a=this.topics[t].length;e<a;e++)if(this.topics[t][e].token===s)return this.topics[t].splice(e,1),s}return!1}reset(){this.topics={},this.subUid=-1}}class h{constructor(s){n(this,"initialState");n(this,"pubsub");n(this,"_changes");this.initialState=s,this.pubsub=new p,this._changes=b({})}static from(s){return c(new h(s))}get changes(){return this._changes.value}get(s){var t;return(t=this.changes[s])!=null?t:this.initialState[s]}set(s,t){this._changes.value={...this.changes,[s]:t}}hasChanges(s){return s?s in this.changes:Object.keys(this.changes).length>0}hasChangesDeep(s){return s in this.changes&&!r.exports.isEqual(this.initialState[s],this.changes[s])}get state(){return{...this.initialState,...this.changes}}resetChanges(){const s={...this.changes};this._changes.value={},this.pubsub.publish("update",s)}onUpdate(s){this.pubsub.subscribe("update",s)}commit(){this.initialState=this.state,this._changes.value={}}toDTO(){return{...this.state,...this._changes.value}}update(s){this._changes.value={...this.changes,...s}}}class l extends h{constructor(t,e){super(e);n(this,"api");this.api=t}static create(t,e){return c(new l(t,e))}getInitialState(t){return this.initialState[t]}updateInitialState(t,e){this.initialState[t]=e,delete this._changes.value[t]}async save(t){if(Object.keys(this.changes).length===0||t&&!(t in this.changes))return;if(t){const a={[t]:this.changes[t]},u=await this.api.update(this.initialState.id,a);this.initialState={...this.initialState,...u},delete this._changes.value[t];return}this.initialState=await this.api.update(this.initialState.id,this.changes);const e={...this.changes};this._changes.value={},this.pubsub.publish("update",e)}}class g extends h{constructor(t,e){super(e);n(this,"api");n(this,"debouncedSave");this.api=t,this.debouncedSave=r.exports.debounce(()=>{this.save()},500)}static create(t,e){return c(new g(t,e))}getInitialState(t){return this.initialState[t]}updateInitialState(t,e){this.initialState[t]=e,delete this._changes.value[t]}set(t,e){super.set(t,e),this.debouncedSave()}async save(t){if(Object.keys(this.changes).length===0||t&&!(t in this.changes))return;if(t){const a={[t]:this.changes[t]},u=await this.api.update(this.initialState.id,a);this.initialState={...this.initialState,...u},delete this._changes.value[t];return}this.initialState=await this.api.update(this.initialState.id,this.changes);const e={...this.changes};this._changes.value={},this.pubsub.publish("update",e)}}export{g as A,h as E,p as P,l as a};
//# sourceMappingURL=record.7f43486c.js.map
