define(["events","appSettings","dom","globalize","appHeader","localsync","emby-checkbox","emby-select","emby-input","emby-button","paper-icon-button-light","emby-scroller"],function(events,appSettings,dom,globalize,appHeader,localSync){"use strict";function onAndroidSyncLocationChange(){MainActivity.authorizeStorage()}function loadForm(view){view.querySelector(".txtSyncPath").value=appSettings.syncPath()||"",view.querySelector(".chkWifi").checked=appSettings.syncOnlyOnWifi(),view.querySelector(".selectAudioBitrate").value=appSettings.maxStaticMusicBitrate()||"",window.AndroidAppSettings&&function(view){for(var html='<option value="">'+globalize.translate("InternalStorage")+"</option>",dirs=AndroidAppHost.getWritableExternalStorageDirs(),size=dirs.size(),i=0;i<size;i++){var dir=dirs.get(i),name=dir.getName(),uuid=dir.getUuid();html+='<option value="'+(uuid?uuid:"%externalstorage%")+'">'+globalize.translate("ExternalStorage")+" ("+name+")</option>"}var selectSyncLocation=view.querySelector(".selectSyncLocation");selectSyncLocation.innerHTML=html,selectSyncLocation.value=appSettings.syncPath()||""}(view)}function saveUser(view){window.AndroidAppSettings?(appSettings.syncPath(view.querySelector(".selectSyncLocation").value),AndroidAppSettings.setSyncPath(view.querySelector(".selectSyncLocation").value),AndroidAppSettings.setSyncOnlyOnWifi(view.querySelector(".chkWifi").checked)):appSettings.syncPath(view.querySelector(".txtSyncPath").value),appSettings.syncOnlyOnWifi(view.querySelector(".chkWifi").checked),appSettings.maxStaticMusicBitrate(view.querySelector(".selectAudioBitrate").value||null),require(["localsync"],function(localSync){localSync.sync()})}function selectDownloadPathWindows(){var inputContainer=this.closest(".inputContainer"),folderPicker=new Windows.Storage.Pickers.FolderPicker;folderPicker.suggestedStartLocation=Windows.Storage.Pickers.PickerLocationId.desktop,folderPicker.fileTypeFilter.replaceAll(["*"]),folderPicker.pickSingleFolderAsync().then(function(folder){folder?(Windows.Storage.AccessCache.StorageApplicationPermissions.futureAccessList.addOrReplace("PickedFolderToken",folder),inputContainer.querySelector(".txtSyncPath").value=folder.path,appSettings.syncPath(folder.path),console.log("Picked folder: "+folder.path)):console.log("Operation cancelled.")})}return function(view,params){var progressContainer=view.querySelector(".progressContainer"),itemProgressBarForeground=view.querySelector(".itemProgressBarForeground"),progressDescription=view.querySelector(".progressDescription");function onDownloadProgress(e,progressInfo){var numItems=progressInfo.numItems||0,numItemsComplete=progressInfo.numItemsComplete||0,pctComplete=progressInfo.totalPercentComplete||0;itemProgressBarForeground.style.width=pctComplete+"%",progressDescription.innerHTML=globalize.translate("DownloadNumItems",numItemsComplete+1,numItems),numItems&&pctComplete<100?progressContainer.classList.remove("hide"):progressContainer.classList.add("hide")}window.AndroidAppSettings?(view.querySelector(".fldSyncLocation").classList.remove("hide"),view.querySelector(".selectSyncLocation").addEventListener("change",onAndroidSyncLocationChange)):view.querySelector(".fldSyncLocation").classList.add("hide"),window.Windows?(view.querySelector(".fldCustomSyncPath").classList.remove("hide"),view.querySelector(".btnSelectSyncPath").addEventListener("click",selectDownloadPathWindows)):view.querySelector(".fldCustomSyncPath").classList.add("hide"),view.querySelector("form").addEventListener("submit",function(e){return saveUser.call(view),e.preventDefault(),!1}),view.addEventListener("viewshow",function(){loadForm(this),events.on(localSync,"progress",onDownloadProgress),localSync.setProgressUpdatesEnabled(!0)}),view.addEventListener("viewbeforehide",function(){events.off(localSync,"progress",onDownloadProgress),localSync.setProgressUpdatesEnabled(!1),saveUser(this)})}});