var p=Object.defineProperty;var u=(s,t,e)=>t in s?p(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e;var i=(s,t,e)=>(u(s,typeof t!="symbol"?t+"":t,e),e);import{A as l}from"./utils.3371dfe5.js";class y{async list(){return await(await fetch("/_editor/api/hooks")).json()}async create(){return await(await fetch("/_editor/api/hooks",{method:"POST",headers:{"Content-Type":"application/json"}})).json()}async get(t){return await(await fetch(`/_editor/api/hooks/${t}`)).json()}async update(t,e){return await(await fetch(`/_editor/api/hooks/${t}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})).json()}async delete(t){await fetch(`/_editor/api/hooks/${t}`,{method:"DELETE",headers:{"Content-Type":"application/json"}})}async run(t){await fetch(`/_hooks/${t}`,{method:"POST",headers:{"Content-Type":"application/json"}})}}const a=new y;class n{constructor(t){i(this,"record");this.record=new l(a,t,"path")}static async list(){return(await a.list()).map(e=>new n(e))}static async create(){const t=await a.create();return new n(t)}static async get(t){const e=await a.get(t);return new n(e)}async delete(){await a.delete(this.path)}async duplicate(){return this}disable(){return a.update(this.path,{enabled:!1})}enable(){return a.update(this.path,{enabled:!0})}async save(){await this.record.save(),console.log("save ",this.path)}onUpdate(t){this.record.pubsub.subscribe("update",t)}hasChanges(){return this.record.hasChanges()}get path(){return this.record.get("path")}set path(t){this.record.set("path",t)}get title(){return this.record.get("title")}get enabled(){return this.record.get("enabled")}get file(){return this.record.get("file")}set file(t){this.record.set("file",t)}async run(t){const e=new URLSearchParams(t.query),r=await fetch(`/_hooks/${this.path}?${e.toString()}`,{method:t.method,headers:{"Content-Type":"application/json",...t.headers},body:t.method==="GET"?void 0:t.body}),c=await r.text(),o={};return r.headers.forEach((h,d)=>{o[d]=h}),{status:r.status,headers:o,body:c}}}export{n as H};
//# sourceMappingURL=hooks.039c0cd9.js.map
