define(["exports","./../emby-apiclient/connectionmanager.js","./../common/globalize.js","./../layoutmanager.js","./../dialoghelper/dialoghelper.js","./../emby-elements/emby-scroller/emby-scroller.js","./../emby-elements/emby-select/emby-select.js","./../emby-elements/emby-input/emby-input.js","./../emby-elements/emby-button/paper-icon-button-light.js","./../common/servicelocator.js","./../focusmanager.js","./../common/appsettings.js","./../registrationservices/registrationservices.js","./../approuter.js"],function(_exports,_connectionmanager,_globalize,_layoutmanager,_dialoghelper,_embyScroller,_embySelect,_embyInput,_paperIconButtonLight,_servicelocator,_focusmanager,_appsettings,_registrationservices,_approuter){var currentDialogOptions;function submitJob(dlg,apiClient,userId,syncOptions,form){if(!userId)throw new Error("userId cannot be null");if(!syncOptions)throw new Error("syncOptions cannot be null");var target,selectSyncTarget;if(form)return selectSyncTarget=form.querySelector(".selectSyncTarget"),(target=selectSyncTarget?selectSyncTarget.value:null)?(setJobValues(selectSyncTarget={userId:userId,TargetId:target,ParentId:syncOptions.ParentId,Category:syncOptions.Category},form),syncOptions.items&&syncOptions.items.length&&(selectSyncTarget.ItemIds=(syncOptions.items||[]).map(function(i){return i.Id||i}).join(",")),apiClient.ajax({type:"POST",url:apiClient.getUrl("Sync/Jobs"),data:JSON.stringify(selectSyncTarget),contentType:"application/json",dataType:"json"}).then(function(){_dialoghelper.default.close(dlg),showSubmissionToast(syncOptions.mode),"download"===syncOptions.mode&&syncNow()}),!0):(function(options){Emby.importModule("./modules/common/dialogs/alert.js").then(function(alert){return alert(options)})}(_globalize.default.translate("PleaseSelectDeviceToSyncTo")),!1);throw new Error("form cannot be null")}function showSubmissionToast(mode){var options,mode="convert"===mode?_globalize.default.translate("ConvertingDots"):_globalize.default.translate("DownloadingDots");options=mode,Emby.importModule("./modules/toast/toast.js").then(function(toast){return toast(options)})}function syncNow(){require(["localsync"],function(localSync){localSync.sync()})}function setJobValues(job,form){var txtBitrate=form.querySelector(".txtBitrate"),txtBitrate=(txtBitrate=txtBitrate?txtBitrate.value:null)&&1e6*parseFloat(txtBitrate),txtBitrate=(job.Bitrate=txtBitrate,form.querySelector(".selectQuality")),txtBitrate=(txtBitrate&&(job.Quality=txtBitrate.value,_appsettings.default.set("sync-lastquality",job.Quality||"")),form.querySelector(".selectProfile")),txtBitrate=(txtBitrate&&(job.Profile=txtBitrate.value),form.querySelector(".selectJobContainer")),txtBitrate=(txtBitrate&&(job.Container=txtBitrate.value),form.querySelector(".selectVideoCodec")),txtBitrate=(txtBitrate&&(job.VideoCodec=txtBitrate.value),form.querySelector(".selectAudioCodec")),txtBitrate=(txtBitrate&&(job.AudioCodec=txtBitrate.value),form.querySelector(".txtItemLimit")),txtBitrate=(txtBitrate&&(job.ItemLimit=txtBitrate.value||null),form.querySelector(".chkSyncNewContent")),txtBitrate=(txtBitrate&&(job.SyncNewContent=txtBitrate.checked),form.querySelector(".chkUnwatchedOnly"));txtBitrate&&(job.UnwatchedOnly=txtBitrate.checked)}function renderForm(options){return new Promise(function(resolve,reject){require(["emby-checkbox","emby-input","emby-select"],function(){!function(options,defaultTargetId,resolve){var elem=options.elem,dialogOptions=options.dialogOptions,targets=dialogOptions.Targets,html="",mode=options.mode,targetContainerClass="download"===mode?" hide":"",syncTargetLabel="convert"===mode?_globalize.default.translate("LabelConvertTo"):_globalize.default.translate("LabelDownloadTo");"download"===mode&&(targets=targets.filter(function(t){return defaultTargetId===t.Id}));options.readOnlySyncTarget?html=(html+='