define(["appSettings","events","globalize","loading","connectionManager","cameraUpload","emby-checkbox","emby-scroller","indicators"],function(appSettings,events,globalize,loading,connectionManager,cameraUpload){"use strict";function reloadUploadFolders(page){page.querySelector(".chkUploadServer:checked")?cameraUpload.getAvailableFolders().then(function(allFolders){!function(page,folders){var uploadAll=appSettings.cameraUploadAllFolders(),uploadFolders=appSettings.cameraUploadFolders();page.querySelector(".uploadFolderList").innerHTML=folders.map(function(s){return'<label><input type="checkbox" is="emby-checkbox"'+(uploadAll||-1!==uploadFolders.indexOf(s.Id)?"checked":" ")+' class="chkUploadFolder" data-id="'+s.Id+'"/><span>'+s.Name+"</span></label>"}).join("")}(page,allFolders),page.querySelector(".fldUploadFolders").classList.remove("hide")}):page.querySelector(".fldUploadFolders").classList.add("hide")}function saveUser(page){for(var chkUploadServer=page.querySelectorAll(".chkUploadServer"),cameraUploadServers=[],i=0,length=chkUploadServer.length;i<length;i++)chkUploadServer[i].checked&&cameraUploadServers.push(chkUploadServer[i].getAttribute("data-id"));appSettings.cameraUploadServers(cameraUploadServers),appSettings.cameraUploadOnlyOnWifi(page.querySelector(".chkWifi").checked),appSettings.cameraUploadAllFolders(!1);var cameraUploadFolders=[],chkUploadFolder=page.querySelectorAll(".chkUploadFolder");for(i=0,length=chkUploadFolder.length;i<length;i++)chkUploadFolder[i].checked&&cameraUploadFolders.push(chkUploadFolder[i].getAttribute("data-id"));appSettings.cameraUploadFolders(cameraUploadFolders),loading.hide()}return function(view,params){var progressContainer=view.querySelector(".progressContainer"),itemProgressBarForeground=view.querySelector(".itemProgressBarForeground"),progressDescription=view.querySelector(".progressDescription");function onUploadProgress(e,progressInfo){var numItems=progressInfo.numItems||0,numItemsComplete=progressInfo.numItemsComplete||0,pctComplete=progressInfo.totalPercentComplete||0;itemProgressBarForeground.style.width=pctComplete+"%",progressDescription.innerHTML=globalize.translate("UploadingNumItems",numItemsComplete+1,numItems),numItems&&pctComplete<100?progressContainer.classList.remove("hide"):progressContainer.classList.add("hide")}view.querySelector(".premiereInfo").innerHTML=globalize.translate("FeatureRequiresEmbyPremiere",'<a href="https://emby.media/premiere" data-preset="premiereinfo" is="emby-linkbutton" type="button" class="button-link">',"</a>"),view.querySelector(".uploadServerList").addEventListener("change",function(e){return reloadUploadFolders(view),e.preventDefault(),!1}),view.querySelector("form").addEventListener("submit",function(e){return loading.show(),saveUser(view),e.preventDefault(),!1}),view.addEventListener("viewshow",function(){!function(page){var uploadServers=appSettings.cameraUploadServers();page.querySelector(".chkWifi").checked=appSettings.cameraUploadOnlyOnWifi(),page.querySelector(".uploadServerList").innerHTML=connectionManager.getSavedServers().map(function(s){return'<label><input type="checkbox" is="emby-checkbox"'+(-1===uploadServers.indexOf(s.Id)?"":" checked")+' class="chkUploadServer" data-id="'+s.Id+'"/><span>'+s.Name+"</span></label>"}).join(""),reloadUploadFolders(page)}(this),cameraUpload.start(),events.on(cameraUpload,"progress",onUploadProgress),cameraUpload.setProgressUpdatesEnabled(!0)}),view.addEventListener("viewbeforehide",function(){saveUser(this),events.off(cameraUpload,"progress",onUploadProgress),cameraUpload.setProgressUpdatesEnabled(!1)})}});