var g=Object.defineProperty;var l=(s,t,e)=>t in s?g(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e;var i=(s,t,e)=>(l(s,typeof t!="symbol"?t+"":t,e),e);import{eM as h,G as d,eN as o}from"./outputWidgets.be3472c2.js";import{P as p}from"./pubsub.1063a0da.js";(function(){try{var s=typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},t=new Error().stack;t&&(s._sentryDebugIds=s._sentryDebugIds||{},s._sentryDebugIds[t]="a920683e-30e7-420e-ac75-07a7dfda07d6",s._sentryDebugIdIdentifier="sentry-dbid-a920683e-30e7-420e-ac75-07a7dfda07d6")}catch{}})();class n{constructor(t){i(this,"initialState");i(this,"pubsub");i(this,"_changes");this.initialState=t,this.pubsub=new p,this._changes=d({})}static from(t){return h(new n(t))}get changes(){return this._changes.value}get(t){var e;return(e=this.changes[t])!=null?e:this.initialState[t]}set(t,e){this._changes.value={...this.changes,[t]:e}}hasChanges(t){return t?t in this.changes:Object.keys(this.changes).length>0}hasChangesDeep(t){return t in this.changes&&!o.exports.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 u extends n{constructor(e,a){super(a);i(this,"api");this.api=e}static create(e,a){return h(new u(e,a))}getInitialState(e){return this.initialState[e]}updateInitialState(e,a){this.initialState[e]=a,delete this._changes.value[e]}async save(e){if(Object.keys(this.changes).length===0||e&&!(e in this.changes))return;if(e){const r={[e]:this.changes[e]},c=await this.api.update(this.initialState.id,r);this.initialState={...this.initialState,...c},delete this._changes.value[e];return}this.initialState=await this.api.update(this.initialState.id,this.changes);const a={...this.changes};this._changes.value={},this.pubsub.publish("update",a)}}export{u as A,n as E};
//# sourceMappingURL=record.820df198.js.map
