import{t as e}from"./api-base-url-DIb6qukm.js";var t=/^[\w!#$%&'*.^`|~+-]+$/,n=(e,n,r={})=>{if(!t.test(e))throw Error(`Invalid cookie name`);let i=`${e}=${n}`;if(e.startsWith(`__Secure-`)&&!r.secure)throw Error(`__Secure- Cookie must have Secure attributes`);if(e.startsWith(`__Host-`)){if(!r.secure)throw Error(`__Host- Cookie must have Secure attributes`);if(r.path!==`/`)throw Error(`__Host- Cookie must have Path attributes with "/"`);if(r.domain)throw Error(`__Host- Cookie must not have Domain attributes`)}for(let e of[`domain`,`path`])if(r[e]&&/[;\r\n]/.test(r[e]))throw Error(`${e} must not contain ";", "\\r", or "\\n"`);if(r&&typeof r.maxAge==`number`&&r.maxAge>=0){if(r.maxAge>3456e4)throw Error(`Cookies Max-Age SHOULD NOT be greater than 400 days (34560000 seconds) in duration.`);i+=`; Max-Age=${r.maxAge|0}`}if(r.domain&&r.prefix!==`host`&&(i+=`; Domain=${r.domain}`),r.path&&(i+=`; Path=${r.path}`),r.expires){if(r.expires.getTime()-Date.now()>3456e7)throw Error(`Cookies Expires SHOULD NOT be greater than 400 days (34560000 seconds) in the future.`);i+=`; Expires=${r.expires.toUTCString()}`}if(r.httpOnly&&(i+=`; HttpOnly`),r.secure&&(i+=`; Secure`),r.sameSite&&(i+=`; SameSite=${r.sameSite.charAt(0).toUpperCase()+r.sameSite.slice(1)}`),r.priority&&(i+=`; Priority=${r.priority.charAt(0).toUpperCase()+r.priority.slice(1)}`),r.partitioned){if(!r.secure)throw Error(`Partitioned Cookie must have Secure attributes`);i+=`; Partitioned`}return i},r=(e,t,r)=>(t=encodeURIComponent(t),n(e,t,r)),i=(e,t)=>(e=e.replace(/\/+$/,``),e+=`/`,t=t.replace(/^\/+/,``),e+t),a=(e,t)=>{for(let[n,r]of Object.entries(t)){let t=RegExp(`/:`+n+`(?:{[^/]+})?\\??`);e=e.replace(t,r?`/${r}`:``)}return e},o=e=>{let t=new URLSearchParams;for(let[n,r]of Object.entries(e))if(r!==void 0)if(Array.isArray(r))for(let e of r)t.append(n,e);else t.set(n,r);return t},s=(e,t)=>{switch(t){case`ws`:return e.replace(/^http/,`ws`);case`http`:return e.replace(/^ws/,`http`)}},c=e=>/^https?:\/\/[^\/]+?\/index(?=\?|$)/.test(e)?e.replace(/\/index(?=\?|$)/,`/`):e.replace(/\/index(?=\?|$)/,``);function l(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function u(e,t){if(!l(e)&&!l(t))return t;let n={...e};for(let e in t){let r=t[e];l(n[e])&&l(r)?n[e]=u(n[e],r):n[e]=r}return n}var d=(e,t)=>new Proxy(()=>{},{get(n,r){if(!(typeof r!=`string`||r===`then`))return d(e,[...t,r])},apply(n,r,i){return e({path:t,args:i})}}),f=class{url;method;buildSearchParams;queryParams=void 0;pathParams={};rBody;cType=void 0;constructor(e,t,n){this.url=e,this.method=t,this.buildSearchParams=n.buildSearchParams}fetch=async(e,t)=>{if(e){if(e.query&&(this.queryParams=this.buildSearchParams(e.query)),e.form){let t=new FormData;for(let[n,r]of Object.entries(e.form))if(r!==void 0)if(Array.isArray(r))for(let e of r)t.append(n,e);else t.append(n,r);this.rBody=t}e.json&&(this.rBody=JSON.stringify(e.json),this.cType=`application/json`),e.param&&(this.pathParams=e.param)}let n=this.method.toUpperCase(),i={...e?.header,...typeof t?.headers==`function`?await t.headers():t?.headers};if(e?.cookie){let t=[];for(let[n,i]of Object.entries(e.cookie))t.push(r(n,i,{path:`/`}));i.Cookie=t.join(`,`)}this.cType&&(i[`Content-Type`]=this.cType);let o=new Headers(i??void 0),s=this.url;s=c(s),s=a(s,this.pathParams),this.queryParams&&(s=s+`?`+this.queryParams.toString()),n=this.method.toUpperCase();let l=!(n===`GET`||n===`HEAD`);return(t?.fetch||fetch)(s,{body:l?this.rBody:void 0,method:n,headers:o,...t?.init})}},p=(e,t)=>d(function n(r){let l=t?.buildSearchParams??o,d=[...r.path],p=d.slice(-3).reverse();if(p[0]===`toString`)return p[1]===`name`?p[2]||``:n.toString();if(p[0]===`valueOf`)return p[1]===`name`?p[2]||``:n;let m=``;if(/^\$/.test(p[0])){let e=d.pop();e&&(m=e.replace(/^\$/,``))}let h=i(e,d.join(`/`));if(m===`url`||m===`path`){let t=h;return r.args[0]&&(r.args[0].param&&(t=a(h,r.args[0].param)),r.args[0].query&&(t=t+`?`+l(r.args[0].query).toString())),t=c(t),m===`url`?new URL(t):t.slice(e.replace(/\/+$/,``).length).replace(/^\/?/,`/`)}if(m===`ws`){let e=s(r.args[0]&&r.args[0].param?a(h,r.args[0].param):h,`ws`),n=new URL(e),i=r.args[0]?.query;return i&&Object.entries(i).forEach(([e,t])=>{Array.isArray(t)?t.forEach(t=>n.searchParams.append(e,t)):n.searchParams.set(e,t)}),((...e)=>t?.webSocket!==void 0&&typeof t.webSocket==`function`?t.webSocket(...e):new WebSocket(...e))(n.toString())}let g=new f(h,m,{buildSearchParams:l});if(m){t??={};let e=u(t,{...r.args[1]});return g.fetch(r.args[0],e)}return g},[]);function m(e=``,t){return p(e,t)}function h(t=e(),n){return m(t,n)}export{h as t};