define(["appSettings","dom","globalize","emby-checkbox","emby-select","emby-input"],function(appSettings,dom,globalize){"use strict";function fillAndroidLocation(view){var html='<option value="">'+globalize.translate("InternalStorage")+"</option>";AndroidAppHost.isExternalStorageWritable()&&(html+='<option value="%externalstorage%">'+globalize.translate("ExternalStorage")+"</option>");var selectSyncLocation=view.querySelector("#selectSyncLocation");selectSyncLocation.innerHTML=html,selectSyncLocation.value=appSettings.syncPath()||""}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.AndroidSyncSettings&&fillAndroidLocation(view)}function syncNow(){require(["localsync"],function(localSync){localSync.sync()})}function saveUser(){var view=this;window.AndroidSyncSettings?(appSettings.syncPath(view.querySelector("#selectSyncLocation").value),AndroidSyncSettings.setSyncPath(view.querySelector("#selectSyncLocation").value),AndroidSyncSettings.setSyncOnlyOnWifi(view.querySelector("#chkWifi").checked)):appSettings.syncPath(view.querySelector("#txtSyncPath").value),appSettings.syncOnlyOnWifi(view.querySelector("#chkWifi").checked),appSettings.maxStaticMusicBitrate(view.querySelector(".selectAudioBitrate").value||null),syncNow()}function selectDownloadPathWindows(){var inputContainer=dom.parentWithClass(this,"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){window.AndroidSyncSettings?(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),Emby.Page.setTitle(globalize.translate("sharedcomponents#Downloads"))}),view.addEventListener("viewbeforehide",saveUser)}});