var l=Object.defineProperty;var u=(s,t,r)=>t in s?l(s,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):s[t]=r;var d=(s,t,r)=>(u(s,typeof t!="symbol"?t+"":t,r),r);import{A as w}from"./activeRecord.3d3c7835.js";import{d as y,w as c}from"./runnerData.bd24d7de.js";import"./registerWidgets.89616af0.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]="d09c4e95-b0c5-4e41-9cef-6ed102bbef73",s._sentryDebugIdIdentifier="sentry-dbid-d09c4e95-b0c5-4e41-9cef-6ed102bbef73")}catch{}})();function p(s){return Object.entries(s).reduce((t,[r,o])=>{var n;if(o.type in c){const e=o;if(!e.id)throw new Error("Widget must have an id");return{...t,[r]:{events:e.events,id:e.id,props:e.props,position:{rowStart:e.rowStart,rowEnd:e.rowEnd,colStart:e.colStart,colEnd:e.colEnd},type:e.type,variable:(n=e.variable)!=null?n:null}}}else{const e=o;return{...t,[r]:{id:e.id,props:e.props,row:e.row,height:e.height,type:e.type,slot:p(e.slot),order:e.order}}}},{})}function h(s){return Object.entries(s).reduce((t,[r,o])=>{var n;if(o.type in c){const e=o;return{...t,[r]:{id:e.id,name:e.id,type:e.type,colStart:e.position.colStart,colEnd:e.position.colEnd,rowStart:e.position.rowStart,rowEnd:e.position.rowEnd,props:e.props,events:e.events,variable:(n=e.variable)!=null?n:void 0}}}else{const e=o;return{...t,[r]:{id:e.id,type:e.type,row:e.row,height:e.height,order:0,props:e.props,slot:h(e.slot)}}}},{})}class f{async list(){return await(await fetch("/_editor/api/dashes")).json()}async create(){return await(await fetch("/_editor/api/dashes",{method:"POST",headers:{"Content-Type":"application/json"}})).json()}async get(t){return await(await fetch(`/_editor/api/dashes/${t}`)).json()}async update(t,r){return await(await fetch(`/_editor/api/dashes/${t}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)})).json()}async delete(t){await fetch(`/_editor/api/dashes/${t}`,{method:"DELETE",headers:{"Content-Type":"application/json"}})}async duplicate(t){return await(await fetch(`/_editor/api/dashes/${t}/duplicate`,{method:"POST",headers:{"Content-Type":"application/json"}})).json()}async addVariableToCode(t,r){await fetch(`/_editor/api/dashes/${t}/add-variable`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({variable:r})})}}const a=new f;class i{constructor(t){d(this,"record");this.record=w.create(a,t,"path")}static from(t){return new i(t)}static async list(){return(await a.list()).map(r=>new i(r))}static async create(){const t=await a.create();return new i(t)}static async get(t){const r=await a.get(t);return new i(r)}get path(){return this.record.get("path")}set path(t){this.record.set("path",t)}get file(){return this.record.get("file")}set file(t){this.record.set("file",t)}get title(){return this.record.get("title")}set title(t){this.record.set("title",t)}get layout(){const t=this.record.get("layout");return{version:"0.2",props:t.props,slot:h(t.slot)}}set layout(t){if(t.version==="0.1")throw new Error("TODO: convert 0.1 to 0.2");const r={version:"0.2",props:t.props,slot:p(t.slot)};this.record.set("layout",r)}async save(){await this.record.save()}onUpdate(t){this.record.pubsub.subscribe("update",t)}hasChanges(){return this.record.hasChanges()}async delete(){await a.delete(this.path)}async duplicate(){const t=await a.duplicate(this.path);return new i(t)}async addVariableToCode(t){await a.addVariableToCode(this.path,t)}get rootSlot(){if(this.layout.version==="0.1")throw new Error("TODO: convert 0.1 to 0.2");return this.layout.slot}makeRunnerData(t,r){return{...t.makeRunnerData(),id:this.path,path:this.path,title:this.title,layout:y(r!=null?r:this.layout),workspaceName:"Untitled Workspace",runtimeType:"dash"}}get routeName(){return"dash"}}export{i as D};
//# sourceMappingURL=dashes.f8616397.js.map
