import{a as u}from"./chunk-RKMHWDGH.js";import{a as f}from"./chunk-FEIY7W7S.js";var T={};f(T,{Body:()=>i,Client:()=>p,Response:()=>m,ResponseType:()=>c,fetch:()=>y,getClient:()=>d});var c=(s=>(s[s.JSON=1]="JSON",s[s.Text=2]="Text",s[s.Binary=3]="Binary",s))(c||{}),i=class{constructor(e,r){this.type=e,this.payload=r}static form(e){let r={},s=(n,t)=>{if(t!==null){let a;typeof t=="string"?a=t:t instanceof Uint8Array||Array.isArray(t)?a=Array.from(t):t instanceof File?a={file:t.name,mime:t.type,fileName:t.name}:typeof t.file=="string"?a={file:t.file,mime:t.mime,fileName:t.fileName}:a={file:Array.from(t.file),mime:t.mime,fileName:t.fileName},r[String(n)]=a}};if(e instanceof FormData)for(let[n,t]of e)s(n,t);else for(let[n,t]of Object.entries(e))s(n,t);return new i("Form",r)}static json(e){return new i("Json",e)}static text(e){return new i("Text",e)}static bytes(e){return new i("Bytes",Array.from(e instanceof ArrayBuffer?new Uint8Array(e):e))}},m=class{constructor(e){this.url=e.url,this.status=e.status,this.ok=this.status>=200&&this.status<300,this.headers=e.headers,this.rawHeaders=e.rawHeaders,this.data=e.data}},p=class{constructor(e){this.id=e}async drop(){return u({__tauriModule:"Http",message:{cmd:"dropClient",client:this.id}})}async request(e){let r=!e.responseType||e.responseType===1;return r&&(e.responseType=2),u({__tauriModule:"Http",message:{cmd:"httpRequest",client:this.id,options:e}}).then(s=>{let n=new m(s);if(r){try{n.data=JSON.parse(n.data)}catch(t){if(n.ok&&n.data==="")n.data={};else if(n.ok)throw Error(`Failed to parse response \`${n.data}\` as JSON: ${t}; try setting the \`responseType\` option to \`ResponseType.Text\` or \`ResponseType.Binary\` if the API does not return a JSON response.`)}return n}return n})}async get(e,r){return this.request({method:"GET",url:e,...r})}async post(e,r,s){return this.request({method:"POST",url:e,body:r,...s})}async put(e,r,s){return this.request({method:"PUT",url:e,body:r,...s})}async patch(e,r){return this.request({method:"PATCH",url:e,...r})}async delete(e,r){return this.request({method:"DELETE",url:e,...r})}};async function d(o){return u({__tauriModule:"Http",message:{cmd:"createClient",options:o}}).then(e=>new p(e))}var l=null;async function y(o,e){return l===null&&(l=await d()),l.request({url:o,method:e?.method??"GET",...e})}export{c as a,i as b,m as c,p as d,d as e,y as f,T as g};