(function(n){n.fn.filedrop=function(t){var l=function(n,t){return n=Math.ceil(n),t=Math.floor(t),Math.floor(Math.random()*(t-n+1))+n},r=l(1,Number.MAX_SAFE_INTEGER),a=t.Accept.split(/\s*,\s*/).map(function(n){return n.substring(1).toUpperCase()}),i=[],v=function(n){var t=n.name.lastIndexOf(".");return t!==-1?n.name.substring(t+1).toUpperCase():null},y=function(){var n=1,t;do{t=!1;for(let r=0;r<i.length;r++)if(i[r].id===n){n+=1;t=!0;break}}while(t);return n},f=function(n){n=n||event;n.preventDefault();n.stopPropagation()},p=function(t){for(var u=0;u<i.length;u++)if(i[u].id===t)break;u<i.length&&(i.splice(u,1),n("#filedrop-"+r).find("#fileupload-"+t).remove(),i.length===0&&n("#filedrop-"+r).find(".chooseFilesLabel").removeClass("hidden"))},w=function(t){for(var f,e,o,u=0;u<i.length;u++)if(i[u].id===t)break;u<i.length&&u!==0&&(f=i[u-1].id,e=i[u-1],i[u-1]=i[u],i[u]=e,o=n("#filedrop-"+r+" > #fileupload-"+t).detach(),n("#filedrop-"+r+" > #fileupload-"+f).before(o))},b=function(t){for(var f,e,o,u=0;u<i.length;u++)if(i[u].id===t)break;u<i.length&&u!==i.length-1&&(f=i[u+1].id,e=i[u+1],i[u+1]=i[u],i[u]=e,o=n("#filedrop-"+r+" > #fileupload-"+t).detach(),n("#filedrop-"+r+" > #fileupload-"+f).after(o))},k=function(u){var e=y(),a=u.name,h=null,c=null,l,o,s;if(t.UseSorting){h=n('                    <a class="fileMoveUpLink">                        <i class="fa fa-arrow-up"><\/i>                    <\/a>                ');c=n('                    <a class="fileMoveDownLink">                        <i class="fa fa-arrow-down"><\/i>                    <\/a>                ');h.find("i").on("click",function(){w(e)});c.find("i").on("click",function(){b(e)})}l=n('                <a class="fileRemoveLink">                    <i class="fa fa-times"><\/i>                <\/a>            ');l.find("i").on("click",function(){p(e)});o=n('                <span class="filename">                    <label class="custom-file-upload" style="display:inline">'+a+"<\/label>                <\/span>            ");h!==null&&c!==null&&(o.append(h),o.append(c));o.append(l);s=n('<div id="fileupload-'+e+'" class="fileupload"><\/div>');s.on("dragover",f);s.on("drop",f);s.append(o);n("#filedrop-"+r).append(s);i.push({id:e,file:u,name:a})},e=function(n=1,r=undefined){var o,s,f,u,e;if(r===undefined&&(r=t.MaximumUploadFiles),i.length){if(i.length<n||i.length>r)return t.showAlert(t.FileAmountMessage),null;for(o=new FormData,e=0;e<i.length;e++)if(u=i[e],s=u.name.lastIndexOf("."),f=s>=0?u.name.substring(s+1).toUpperCase():null,f!==null&&t.UploadOptions.indexOf(f)!==-1)o.append(u.id,u.file,u.name);else return t.showAlert(t.FileWrongTypeMessage+f),null;return o}return t.showAlert(t.FileSelectMessage),null},s=function(u){var o=!1,s,f,e;if(u.target.files&&u.target.files.length)if(s=u.target.files.length+i.length,s<=t.MaximumUploadFiles)for(t.hideAlert(),e=0;e<u.target.files.length;e++)f=v(u.target.files[e]),f!==null&&a.indexOf(f)!==-1?(n("#filedrop-"+r).find(".chooseFilesLabel").addClass("hidden"),k(u.target.files[e])):(o=!0,f!==null&&(f=f.toUpperCase()),t.showAlert(t.FileWrongTypeMessage+f));else o=!0,t.showAlert(t.FileAmountMessage),window.setTimeout(function(){t.hideAlert()},5e3);return n("input#UploadFileInput-"+r).val(""),!o},d=function(i){if(t.showLoader(),s(i)){var r=e();r!==null&&n.ajax({method:"POST",url:t.APIBasePath+"Common/UploadFile",data:r,processData:!1,contentType:!1,cache:!1,timeout:6e5,success:t.Method,xhr:function(){var i=n.ajaxSettings.xhr();return i.upload&&i.upload.addEventListener("progress",t.progress,!1),i},error:function(n){t.showAlert(n.Status)}})}},h=o.AppName==="Comparison",u='            <div class="filedrop filedrop-mvc fileplacement" id="filedrop-'+r+'"'+(h?'style="padding:30px 0"':"")+'>                <label for="UploadFileInput-'+r+'" style="margin-top: 50px;text-decoration: underline">'+t.DropFilesPrompt+'<\/label>                <input type="file" class="uploadfileinput" id="UploadFileInput-'+r+'" name="UploadFileInput-'+r+'"                    title=""                    accept="'+t.Accept+'"'+(t.Multiple?'multiple="'+t.Multiple+'"':"")+"/>            <\/div>",c;if(h&&(u='\t\t\t\t\t<div class="col-md-6 col-sm-12">'+u+"\t\t\t\t\t<\/div>"),c=n(u),this.prepend(c),t.UploadAndRedirect)n("input#UploadFileInput-"+r).on("change",d);else n("input#UploadFileInput-"+r).on("change",s);return{get droppedFiles(){return i},get prepareFormData(){return e}}}})(jQuery);