/*! UIkit 3.20.4-dev.c54f44b4f | https://www.getuikit.com | (c) 2014 - 2024 YOOtheme | MIT License */import{noop as o,matches as g,removeClass as m,addClass as v,toArray as S,trigger as w,on as n,assign as d}from"uikit-util";var x={props:{i18n:Object},data:{i18n:null},methods:{t(t,...r){var s,a,e;let i=0;return((e=((s=this.i18n)==null?void 0:s[t])||((a=this.$options.i18n)==null?void 0:a[t]))==null?void 0:e.replace(/%s/g,()=>r[i++]||""))||""}}},c={mixins:[x],i18n:{invalidMime:"Invalid File Type: %s",invalidName:"Invalid File Name: %s",invalidSize:"Invalid File Size: %s Kilobytes Max"},props:{allow:String,clsDragover:String,concurrent:Number,maxSize:Number,method:String,mime:String,multiple:Boolean,name:String,params:Object,type:String,url:String},data:{allow:!1,clsDragover:"uk-dragover",concurrent:1,maxSize:0,method:"POST",mime:!1,multiple:!1,name:"files[]",params:{},type:"",url:"",abort:o,beforeAll:o,beforeSend:o,complete:o,completeAll:o,error:o,fail:o,load:o,loadEnd:o,loadStart:o,progress:o},events:{change(t){g(t.target,'input[type="file"]')&&(t.preventDefault(),t.target.files&&this.upload(t.target.files),t.target.value="")},drop(t){l(t);const r=t.dataTransfer;r!=null&&r.files&&(m(this.$el,this.clsDragover),this.upload(r.files))},dragenter(t){l(t)},dragover(t){l(t),v(this.$el,this.clsDragover)},dragleave(t){l(t),m(this.$el,this.clsDragover)}},methods:{async upload(t){if(t=S(t),!t.length)return;w(this.$el,"upload",[t]);for(const a of t){if(this.maxSize&&this.maxSize*1e3<a.size){this.fail(this.t("invalidSize",this.maxSize));return}if(this.allow&&!f(this.allow,a.name)){this.fail(this.t("invalidName",this.allow));return}if(this.mime&&!f(this.mime,a.type)){this.fail(this.t("invalidMime",this.mime));return}}this.multiple||(t=t.slice(0,1)),this.beforeAll(this,t);const r=y(t,this.concurrent),s=async a=>{const e=new FormData;a.forEach(i=>e.append(this.name,i));for(const i in this.params)e.append(i,this.params[i]);try{const i=await b(this.url,{data:e,method:this.method,responseType:this.type,beforeSend:h=>{const{xhr:p}=h;n(p.upload,"progress",this.progress);for(const u of["loadStart","load","loadEnd","abort"])n(p,u.toLowerCase(),this[u]);return this.beforeSend(h)}});this.complete(i),r.length?await s(r.shift()):this.completeAll(i)}catch(i){this.error(i)}};await s(r.shift())}}};function f(t,r){return r.match(new RegExp(`^${t.replace(/\//g,"\\/").replace(/\*\*/g,"(\\/[^\\/]+)*").replace(/\*/g,"[^\\/]+").replace(/((?!\\))\?/g,"$1.")}$`,"i"))}function y(t,r){const s=[];for(let a=0;a<t.length;a+=r)s.push(t.slice(a,a+r));return s}function l(t){t.preventDefault(),t.stopPropagation()}function b(t,r){const s={data:null,method:"GET",headers:{},xhr:new XMLHttpRequest,beforeSend:o,responseType:"",...r};return Promise.resolve().then(()=>s.beforeSend(s)).then(()=>E(t,s))}function E(t,r){return new Promise((s,a)=>{const{xhr:e}=r;for(const i in r)if(i in e)try{e[i]=r[i]}catch{}e.open(r.method.toUpperCase(),t);for(const i in r.headers)e.setRequestHeader(i,r.headers[i]);n(e,"load",()=>{e.status===0||e.status>=200&&e.status<300||e.status===304?s(e):a(d(Error(e.statusText),{xhr:e,status:e.status}))}),n(e,"error",()=>a(d(Error("Network Error"),{xhr:e}))),n(e,"timeout",()=>a(d(Error("Network Timeout"),{xhr:e}))),e.send(r.data)})}typeof window<"u"&&window.UIkit&&window.UIkit.component("upload",c);export{c as default};
