define(["apphost","globalize","connectionManager","layoutManager","shell","focusManager","scrollHelper","appSettings","registrationServices","dialogHelper","paper-icon-button-light","formDialogStyle"],function(appHost,globalize,connectionManager,layoutManager,shell,focusManager,scrollHelper,appSettings,registrationServices,dialogHelper){"use strict";functionsubmitJob(dlg,apiClient,userId,syncOptions,form){if(!userId)thrownewError("userId cannot be null");if(!syncOptions)thrownewError("syncOptions cannot be null");if(!form)thrownewError("form cannot be null");varselectSyncTarget=form.querySelector("#selectSyncTarget"),target=selectSyncTarget?selectSyncTarget.value:null;if(!target)returnrequire(["toast"],function(toast){toast(globalize.translate("sharedcomponents#PleaseSelectDeviceToSyncTo"))}),!1;varoptions={userId:userId,TargetId:target,ParentId:syncOptions.ParentId,Category:syncOptions.Category};returnsetJobValues(options,form),syncOptions.items&&syncOptions.items.length&&(options.ItemIds=(syncOptions.items||[]).map(function(i){returni.Id||i}).join(",")),apiClient.ajax({type:"POST",url:apiClient.getUrl("Sync/Jobs"),data:JSON.stringify(options),contentType:"application/json",dataType:"json"}).then(function(){dialogHelper.close(dlg),require(["toast"],function(toast){varmsg=target===apiClient.deviceId()?globalize.translate("sharedcomponents#DownloadScheduled"):globalize.translate("sharedcomponents#SyncJobCreated");toast(msg)})}),!0}functionsubmitQuickSyncJob(apiClient,userId,targetId,syncOptions){if(!userId)thrownewError("userId cannot be null");if(!syncOptions)thrownewError("syncOptions cannot be null");if(!targetId)thrownewError("targetId cannot be null");varoptions={userId:userId,TargetId:targetId,ParentId:syncOptions.ParentId,Category:syncOptions.Category,Quality:syncOptions.Quality,Bitrate:syncOptions.Bitrate};returnsyncOptions.items&&syncOptions.items.length&&(options.ItemIds=(syncOptions.items||[]).map(function(i){returni.Id||i}).join(",")),apiClient.ajax({type:"POST",url:apiClient.getUrl("Sync/Jobs"),data:JSON.stringify(options),contentType:"application/json",dataType:"json"}).then(function(){require(["toast"],function(toast){varmsg=targetId===apiClient.deviceId()?globalize.translate("sharedcomponents#DownloadScheduled"):globalize.translate("sharedcomponents#SyncJobCreated");toast(msg)})})}functionsetJobValues(job,form){vartxtBitrate=form.querySelector("#txtBitrate"),bitrate=txtBitrate?txtBitrate.value:null;bitrate&&(bitrate=1e6*parseFloat(bitrate)),job.Bitrate=bitrate;varselectQuality=form.querySelector("#selectQuality");selectQuality&&(job.Quality=selectQuality.value,appSettings.set("sync-lastquality",job.Quality||""));varselectProfile=form.querySelector("#selectProfile");selectProfile&&(job.Profile=selectProfile.value);vartxtItemLimit=form.querySelector("#txtItemLimit");txtItemLimit&&(job.ItemLimit=txtItemLimit.value||null);varchkSyncNewContent=form.querySelector("#chkSyncNewContent");chkSyncNewContent&&(job.SyncNewContent=chkSyncNewContent.checked);varchkUnwatchedOnly=form.querySelector("#chkUnwatchedOnly");chkUnwatchedOnly&&(job.UnwatchedOnly=chkUnwatchedOnly.checked)}functionrenderForm(options){returnnewPromise(function(resolve,reject){require(["emby-checkbox","emby-input","emby-select"],function(){appHost.appInfo().then(function(appInfo){renderFormInternal(options,appInfo,resolve)})})})}functiononHelpLinkClick(e){returnshell.openUrl(this.href),e.preventDefault(),!1}functionrenderFormInternal(options,appInfo,resolve){varelem=options.elem,dialogOptions=options.dialogOptions,targets=dialogOptions.Targets,html="",targetContainerClass=options.isLocalSync?" hide":"";(options.showName||dialogOptions.Options.indexOf("Name")!==-1)&&(html+='<h1 style="margin-top:0;" class="syncJobName '+targetContainerClass+'"></h1>');varsyncTargetLabel=globalize.translate("sharedcomponents#LabelDownloadTo");options.readOnlySyncTarget?(html+='<div class="inputContainer'+targetContainerClass+'">',html+='<input is="emby-input" type="text" id="selectSyncTarget" readonly label="'+syncTargetLabel+'"/