"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const e={method:"GET",timeout:0,headers:{"Content-Type":"application/json"},transformRequest:[(e,t)=>e],transformResponse:[e=>e],adapter:"fetch"};function t(e,t,r){const s=`${e.replace(/\/+$/,"")}/${t.replace(/^\/+/,"")}`;if(!r)return s;const o=Object.keys(r).map((e=>`${encodeURIComponent(e)}=${encodeURIComponent(r[e])}`)).join("&");return o?`${s}?${o}`:s}function r(e,t){const r={...e};return t&&(r.baseURL=t.baseURL||e.baseURL,r.url=t.url||e.url,r.headers={...e.headers,...t.headers},r.params={...e.params,...t.params},r.data=t.data||e.data,r.method=t.method||e.method,r.responseType=t.responseType||e.responseType,r.timeout=t.timeout||e.timeout,r.transformRequest=t.transformRequest||e.transformRequest,r.transformResponse=t.transformResponse||e.transformResponse,r.cancelToken=t.cancelToken||e.cancelToken,r.adapter=t.adapter||e.adapter),r}function s(e,t,r){return r.forEach((r=>{e=r(e,t)})),e}function o(e,t){if(t&&t.includes("application/json"))return JSON.stringify(e);if(t&&t.includes("application/x-www-form-urlencoded"))return new URLSearchParams(e).toString();if(t&&t.includes("multipart/form-data")){const t=new FormData;return Object.keys(e).forEach((r=>{t.append(r,e[r])})),t}return e}const n=e=>{let t="";if("object"==typeof e&&null!==e){if(e.message&&(t+=e.message+"\n"),e.errors&&e.errors.forEach((e=>{e.message&&(t+=e.message+"\n")})),e.response&&e.response.data&&e.response.data.error){const r=e.response.data.error;r.message&&(t+=r.message+"\n")}}else t+=String(e)+"\n";return t.trim()||"Noma'lum xatolik"};class a{constructor(t){this.defaults=r(e,t),this.interceptors={request:new h,response:new h}}async request(e){const a=Date.now(),u=r(this.defaults,e),h=u.baseURL||"";u.url=u.url?t(h,u.url||"",u.params):h;const l=new c(u.headers);u.headers=l.toObject(),u.data&&(u.data=o(u.data,l.get("Content-Type")));try{const e=await function(e){const t="xhr"===e.adapter?i:d;return new Promise(((r,o)=>{e.cancelToken&&e.cancelToken.throwIfRequested(),t(e).then((t=>{try{!function(e){return e.toUpperCase().trim().startsWith("=200&&t.status<300?r(t):o(p.from(new Error(`Request failed with status ${t.status}`),e,void 0,t))):o(p.from(new Error("HTML response received instead of JSON"),e,void 0,t))}catch(r){o(p.from(new Error(`Failed to parse response as JSON: ${n(r)}`),e,void 0,t))}})).catch((t=>{o(p.from(t,e,void 0,void 0))}))}))}(u),t=Date.now();return{...e,duration:t-a,statusText:m[e.status]||"Unknown Status"}}catch(e){const t=Date.now();throw e.duration=t-a,e}}get(e,t={}){return this.request({...t,method:"GET",url:e})}post(e,t,r={}){return this.request({...r,method:"POST",url:e,data:t})}put(e,t,r={}){return this.request({...r,method:"PUT",url:e,data:t})}patch(e,t,r={}){return this.request({...r,method:"PATCH",url:e,data:t})}delete(e,t={}){return this.request({...t,method:"DELETE",url:e})}}class u{constructor(e){if(this.reason=null,"function"!=typeof e)throw new TypeError("executor must be a function.");let t;this.promise=new Promise((e=>{t=e})),e((e=>{this.reason||(this.reason=new Error(e),t(this.reason))}))}throwIfRequested(){if(this.reason)throw this.reason}static source(){let e;return{token:new u((t=>{e=t})),cancel:e}}}class c{constructor(e){this.headers=e||{}}set(e,t){this.headers[e.toLowerCase()]=t}get(e){return this.headers[e.toLowerCase()]}remove(e){delete this.headers[e.toLowerCase()]}toObject(){return{...this.headers}}}function i(e){return new Promise(((t,r)=>{if("undefined"==typeof window||void 0===window.XMLHttpRequest)return void r(new Error("XMLHttpRequest is not supported in Node.js environment."));const{url:s,method:o,headers:n,data:a}=e,u=new XMLHttpRequest;u.open(o.toUpperCase(),s,!0),n&&Object.keys(n).forEach((e=>{u.setRequestHeader(e,n[e])})),u.onload=()=>{const r={data:u.response,status:u.status,statusText:u.statusText,headers:u.getAllResponseHeaders(),config:e,request:u};t(r)},u.onerror=()=>r(new Error("Network Error")),u.ontimeout=()=>r(new Error(`Timeout of ${e.timeout}ms exceeded`)),u.send(a)}))}function d(e){return new Promise(((t,r)=>{if("undefined"==typeof fetch)return void r(new Error("Fetch API not found in this environment."));const{url:s,method:o,headers:n,data:a}=e;fetch(s,{method:o,headers:n,body:a}).then((t=>t.json().then((r=>({data:r,status:t.status,statusText:t.statusText,headers:t.headers,config:e,request:t}))))).then(t).catch((e=>{r(e)}))}))}class h{constructor(){this.handlers=[]}use(e,t){return this.handlers.push({fulfilled:e,rejected:t}),this.handlers.length-1}eject(e){this.handlers[e]&&(this.handlers[e]=null)}forEach(e){this.handlers.forEach((t=>{null!==t&&e(t)}))}}class p extends Error{constructor(e,t,r,s,o){super(e),this.name="FetcherErrorHandler",this.code=t,this.config=r,this.request=s,this.response=o,Error.captureStackTrace&&Error.captureStackTrace(this,p)}static from(e,t,r,s){const o="Error"!==e.name?e.name:void 0;return new p(e.message,o,t,r,s)}}function l(e){const t=new a(e),s=a.prototype.request.bind(t);return Object.setPrototypeOf(s,a.prototype),Object.assign(s,t),s.create=t=>l(r(e,t)),s}const m={200:"OK",201:"Created",202:"Accepted",204:"No Content",400:"Bad Request",401:"Unauthorized",403:"Forbidden",404:"Not Found",500:"Internal Server Error",502:"Bad Gateway",503:"Service Unavailable",504:"Gateway Timeout"},f=l(e);f.create=e=>l(e),exports.CancelToken=u,exports.FetcherErrorHandler=p,exports.FetcherHeaders=c,exports.HTTP_STATUS_CODES=m,exports.InterceptorManager=h,exports.buildURL=t,exports.createInstance=l,exports.default=f,exports.extractErrorMessage=n,exports.fetchAdapter=d,exports.formatRequestBody=o,exports.mergeConfig=r,exports.transformData=s,exports.xhrAdapter=i;