function c(e,r){const n=`cannot ${e.method} ${e.action} ${r.status}'`,s=new Error(n);return s.status=r.status,s.method=e.method,s.url=e.action,s}function u(e){const r=e.responseText||e.response;if(!r)return r;try{return JSON.parse(r)}catch{return r}}function f(e){const r=new XMLHttpRequest;e.onProgress&&r.upload&&(r.upload.onprogress=function(t){t.total>0&&(t.percent=t.loaded/t.total*100),e.onProgress(t)});const n=new FormData;e.data&&Object.keys(e.data).forEach(a=>{const t=e.data[a];if(Array.isArray(t)){t.forEach(d=>{n.append(`${a}[]`,d)});return}n.append(a,t)}),e.file instanceof Blob?n.append(e.filename,e.file,e.file.name):n.append(e.filename,e.file),r.onerror=function(t){e.onError(t)},r.onload=function(){return r.status<200||r.status>=300?e.onError(c(e,r),u(r)):e.onSuccess(u(r),r)},r.open(e.method,e.action,!0),e.withCredentials&&"withCredentials"in r&&(r.withCredentials=!0);const s=e.headers||{};return s["X-Requested-With"]!==null&&r.setRequestHeader("X-Requested-With","XMLHttpRequest"),Object.keys(s).forEach(a=>{s[a]!==null&&r.setRequestHeader(a,s[a])}),r.send(n),{abort(){r.abort()}}}export{f as default};
