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 o=(s,a,e)=>f(s,typeof a!="symbol"?a+"":a,e);import{m as d}from"./module.esm-uXcmRlT3.js";import{b as u,t as m}from"./toast-C5YoKCAA.js";class y extends Error{constructor(a,e){super(e),this.response=a}}class b{constructor(){o(this,"base",null);o(this,"config",{toast:!0})}getDefaultHeaders(){return{"Content-Type":"application/json",Accept:"application/json"}}async request(a="GET",e,t={}){const n={method:a,headers:this.getDefaultHeaders()},i=u();return i&&(n.headers.Authorization=`Bearer ${i}`),d.store("workspace")&&(n.headers["X-Workspace-Id"]=d.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 this.config.toast&&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};
