var l=Object.defineProperty;var f=(s,a,e)=>a in s?l(s,a,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[a]=e;var i=(s,a,e)=>f(s,typeof a!="symbol"?a+"":a,e);import{m as o}from"./module.esm-DfkxB5GV.js";import{a as u,t as m}from"./toast-ClQDZCRA.js";class y extends Error{constructor(a,e){super(e),this.response=a}}class b{constructor(){i(this,"base",null)}getDefaultHeaders(){return{"Content-Type":"application/json",Accept:"application/json"}}async request(a="GET",e,t={}){const n={method:a,headers:this.getDefaultHeaders()},d=u();return d&&(n.headers.Authorization=`Bearer ${d}`),o.store("workspace")&&(n.headers["X-Workspace-Id"]=o.store("workspace").id),e=e instanceof URL?e:new URL(((this.base||"")+"/"+e).replace(/([^:]\/)\/+/g,"$1"),window.location.origin),t.params&&(Object.keys(t.params).forEach(r=>e.searchParams.append(r,t.params[r])),delete t.params),t={...n,...t},t.body&&(t.body instanceof FormData?delete t.headers["Content-Type"]:t.body instanceof URLSearchParams?t.headers["Content-Type"]="application/x-www-form-urlencoded":t.headers["Content-Type"]==="application/json"&&typeof t.body!="string"&&(t.body=JSON.stringify(t.body))),fetch(e,{...n,...t}).then(async r=>{let h=r.clone();if(r.data={},r.headers.get("Content-Type")&&r.headers.get("Content-Type").toLocaleLowerCase().includes("application/json"))try{r.data=await h.json()}catch{}if(r.ok)return r;let c=r.data.message||null;throw c&&(m.error(c),window.modal.close()),new y(r,c||r.statusText)})}get(a,e={},t={}){return this.request("GET",a,{...t,params:e})}post(a,e={},t={}){return this.request("POST",a,{...t,body:e})}patch(a,e={},t={}){return this.request("PATCH",a,{...t,body:e})}put(a,e={},t={}){return this.request("PUT",a,{...t,body:e})}remove(a,e){return this.request("DELETE",a,e)}delete(a,e){return this.remove(a,e)}}export{b as A,y as a};
