'use strict';

var $ = require('axios');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var $__default = /*#__PURE__*/_interopDefault($);

var b=/\{[^{}]+\}/g,u=({allowReserved:n,name:r,value:e})=>{if(e==null)return "";if(typeof e=="object")throw new Error("Deeply-nested arrays/objects aren\u2019t supported. Provide your own `querySerializer()` to handle these.");return `${r}=${n?e:encodeURIComponent(e)}`},x=n=>{switch(n){case"label":return ".";case"matrix":return ";";case"simple":return ",";default:return "&"}},C=n=>{switch(n){case"form":return ",";case"pipeDelimited":return "|";case"spaceDelimited":return "%20";default:return ","}},j=n=>{switch(n){case"label":return ".";case"matrix":return ";";case"simple":return ",";default:return "&"}},z=({allowReserved:n,explode:r,name:e,style:a,value:s})=>{if(!r){let i=(n?s:s.map(c=>encodeURIComponent(c))).join(C(a));switch(a){case"label":return `.${i}`;case"matrix":return `;${e}=${i}`;case"simple":return i;default:return `${e}=${i}`}}let o=x(a),t=s.map(i=>a==="label"||a==="simple"?n?i:encodeURIComponent(i):u({allowReserved:n,name:e,value:i})).join(o);return a==="label"||a==="matrix"?o+t:t},O=({allowReserved:n,explode:r,name:e,style:a,value:s})=>{if(a!=="deepObject"&&!r){let i=[];Object.entries(s).forEach(([d,p])=>{i=[...i,d,n?p:encodeURIComponent(p)];});let c=i.join(",");switch(a){case"form":return `${e}=${c}`;case"label":return `.${c}`;case"matrix":return `;${e}=${c}`;default:return c}}let o=j(a),t=Object.entries(s).map(([i,c])=>u({allowReserved:n,name:a==="deepObject"?`${e}[${i}]`:i,value:c})).join(o);return a==="label"||a==="matrix"?o+t:t},A=({path:n,url:r})=>{let e=r,a=r.match(b);if(a)for(let s of a){let o=!1,t=s.substring(1,s.length-1),i="simple";t.endsWith("*")&&(o=!0,t=t.substring(0,t.length-1)),t.startsWith(".")?(t=t.substring(1),i="label"):t.startsWith(";")&&(t=t.substring(1),i="matrix");let c=n[t];if(c==null)continue;if(Array.isArray(c)){e=e.replace(s,z({explode:o,name:t,style:i,value:c}));continue}if(typeof c=="object"){e=e.replace(s,O({explode:o,name:t,style:i,value:c}));continue}if(i==="matrix"){e=e.replace(s,`;${u({name:t,value:c})}`);continue}let d=encodeURIComponent(i==="label"?`.${c}`:c);e=e.replace(s,d);}return e},S=({path:n,url:r})=>n?A({path:n,url:r}):r,g=(n,r,e)=>{typeof e=="string"||e instanceof Blob?n.append(r,e):n.append(r,JSON.stringify(e));},m=(n,r)=>{let e={...n,...r};return e.headers=f(n.headers,r.headers),e},f=(...n)=>{let r={};for(let e of n){if(!e||typeof e!="object")continue;let a=Object.entries(e);for(let[s,o]of a)if(o===null)delete r[s];else if(Array.isArray(o))for(let t of o)r[s]=[...r[s]??[],t];else o!==void 0&&(r[s]=typeof o=="object"?JSON.stringify(o):o);}return r},R={bodySerializer:n=>{let r=new FormData;return Object.entries(n).forEach(([e,a])=>{a!=null&&(Array.isArray(a)?a.forEach(s=>g(r,e,s)):g(r,e,a));}),r}},P={bodySerializer:n=>JSON.stringify(n)},h=(n,r,e)=>{typeof e=="string"?n.append(r,e):n.append(r,JSON.stringify(e));},w={bodySerializer:n=>{let r=new URLSearchParams;return Object.entries(n).forEach(([e,a])=>{a!=null&&(Array.isArray(a)?a.forEach(s=>h(r,e,s)):h(r,e,a));}),r}},y=(n={})=>({baseURL:"",...n});var U=n=>{let r=m(y(),n),e=$__default.default.create(r),a=()=>({...r}),s=t=>(r=m(r,t),e.defaults={...e.defaults,...r,headers:f(e.defaults.headers,r.headers)},a()),o=async t=>{let i={...r,...t,headers:f(r.headers,t.headers)};i.body&&i.bodySerializer&&(i.body=i.bodySerializer(i.body));let c=S({path:i.path,url:i.url}),d=i.axios||e;try{let p=await d({...i,data:i.body,params:i.query,url:c}),{data:l}=p;return i.responseType==="json"&&i.responseTransformer&&(l=await i.responseTransformer(l)),{...p,data:l??{}}}catch(p){let l=p;if(i.throwOnError)throw l;return l.error=l.response?.data??{},l}};return {delete:t=>o({...t,method:"delete"}),get:t=>o({...t,method:"get"}),getConfig:a,head:t=>o({...t,method:"head"}),instance:e,options:t=>o({...t,method:"options"}),patch:t=>o({...t,method:"patch"}),post:t=>o({...t,method:"post"}),put:t=>o({...t,method:"put"}),request:o,setConfig:s}};

exports.createClient = U;
exports.createConfig = y;
exports.formDataBodySerializer = R;
exports.jsonBodySerializer = P;
exports.urlSearchParamsBodySerializer = w;
//# sourceMappingURL=index.cjs.map
//# sourceMappingURL=index.cjs.map