var h=Object.defineProperty;var r=(s,e,t)=>e in s?h(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t;var i=(s,e,t)=>(r(s,typeof e!="symbol"?e+"":e,t),t);import{P as u}from"./pubsub.98ad9fe0.js";import{G as c,eF as d}from"./outputWidgets.c072fe4e.js";(function(){try{var s=typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},e=new Error().stack;e&&(s._sentryDebugIds=s._sentryDebugIds||{},s._sentryDebugIds[e]="f82f9fbe-0773-4fc9-8944-d47d8b6f9ead",s._sentryDebugIdIdentifier="sentry-dbid-f82f9fbe-0773-4fc9-8944-d47d8b6f9ead")}catch{}})();class n{constructor(e,t,a){i(this,"initialState");i(this,"_changes");i(this,"api");i(this,"idKey");i(this,"pubsub");this.initialState=t,this._changes=c({}),this.api=e,this.idKey=a,this.pubsub=new u}static create(e,t,a=null){return d(new n(e,t,a))}get changes(){return this._changes.value}get(e){var t;return(t=this.changes[e])!=null?t:this.initialState[e]}set(e,t){this._changes.value={...this.changes,[e]:t}}async save(){if(Object.keys(this.changes).length===0)return;if(this.api.update===void 0)throw new Error("update not implemented");this.initialState=await this.api.update(this.idKey?this.initialState[this.idKey]:null,this.changes);const e={...this.changes};this._changes.value={},this.pubsub.publish("update",e)}hasChanges(e){return e?e in this.changes:Object.keys(this.changes).length>0}get state(){return{...this.initialState,...this.changes}}resetChanges(){const e={...this.changes};this._changes.value={},this.pubsub.publish("update",e)}}export{n as A};
//# sourceMappingURL=activeRecord.fdc25b97.js.map
