define(["dom","loading","globalize","apphost","formHelper","emby-checkbox","emby-textarea","emby-input","emby-select","emby-linkbutton"],function(dom,loading,globalize,appHost,formHelper){"use strict";var currentBrandingOptions,currentLanguage;function onSubmit(e){loading.show();var form=this;form.closest(".page");return ApiClient.getServerConfiguration().then(function(config){config.UICulture=form.querySelector("#selectLocalizationLanguage").value,config.CachePath=form.querySelector("#txtCachePath").value;var requiresReload=!1;config.UICulture!==currentLanguage&&(requiresReload=!0),config.RunAtStartup=form.querySelector("#chkRunAtStartup").checked,config.AutoRunWebApp=form.querySelector("#chkRunWebAppAtStartup").checked,config.EnableAutomaticRestart=form.querySelector("#chkEnableAutomaticRestart").checked,config.EnableAutoUpdate=form.querySelector("#chkEnableAutomaticServerUpdates").checked,ApiClient.updateServerConfiguration(config).then(function(){ApiClient.getNamedConfiguration("branding").then(function(brandingConfig){brandingConfig.LoginDisclaimer=form.querySelector("#txtLoginDisclaimer").value,brandingConfig.CustomCss=form.querySelector("#txtCustomCss").value,currentBrandingOptions&&brandingConfig.CustomCss!==currentBrandingOptions.CustomCss&&(requiresReload=!0),ApiClient.updateNamedConfiguration("branding",brandingConfig).then(function(){formHelper.handleConfigurationSavedResponse(),requiresReload&&!appHost.supports("multiserver")&&window.location.reload(!0)})})})}),e.preventDefault(),e.stopPropagation(),!1}return function(view,params){view.querySelector("#btnSelectCachePath").addEventListener("click",function(){require(["directorybrowser"],function(directoryBrowser){var picker=new directoryBrowser;picker.show({callback:function(path){path&&(view.querySelector("#txtCachePath").value=path),picker.close()},validateWriteable:!0,header:globalize.translate("HeaderSelectServerCachePath"),instruction:globalize.translate("HeaderSelectServerCachePathHelp")})})}),view.querySelector(".dashboardGeneralForm").addEventListener("submit",onSubmit),view.addEventListener("viewshow",function(){var promise1=ApiClient.getServerConfiguration(),promise2=ApiClient.getJSON(ApiClient.getUrl("Localization/Options")),promise3=ApiClient.getSystemInfo();Promise.all([promise1,promise2,promise3]).then(function(responses){!function(page,config,languageOptions,systemInfo){-1!==systemInfo.OperatingSystem.toLowerCase().indexOf("windows")?page.querySelector("#windowsStartupDescription").classList.remove("hide"):page.querySelector("#windowsStartupDescription").classList.add("hide"),systemInfo.SupportsAutoRunAtStartup?page.querySelector("#fldRunAtStartup").classList.remove("hide"):page.querySelector("#fldRunAtStartup").classList.add("hide"),systemInfo.CanLaunchWebBrowser?page.querySelector("#fldRunWebAppAtStartup").classList.remove("hide"):page.querySelector("#fldRunWebAppAtStartup").classList.add("hide"),page.querySelector("#txtCachePath").value=config.CachePath||"";var selectLocalizationLanguage=page.querySelector("#selectLocalizationLanguage");selectLocalizationLanguage.innerHTML=languageOptions.map(function(l){return'<option value="'+l.Value+'">'+l.Name+"</option>"}),selectLocalizationLanguage.value=config.UICulture,currentLanguage=config.UICulture,page.querySelector("#chkRunAtStartup").checked=config.RunAtStartup,page.querySelector("#chkRunWebAppAtStartup").checked=config.AutoRunWebApp||!1,systemInfo.CanSelfUpdate?page.querySelector(".fldAutomaticUpdates").classList.remove("hide"):page.querySelector(".fldAutomaticUpdates").classList.add("hide"),page.querySelector("#chkEnableAutomaticServerUpdates").checked=config.EnableAutoUpdate,page.querySelector("#chkEnableAutomaticRestart").checked=config.EnableAutomaticRestart,systemInfo.CanSelfRestart?page.querySelector("#fldEnableAutomaticRestart").classList.remove("hide"):page.querySelector("#fldEnableAutomaticRestart").classList.add("hide"),systemInfo.CanSelfRestart||systemInfo.CanSelfUpdate?page.querySelector(".autoUpdatesContainer").classList.remove("hide"):page.querySelector(".autoUpdatesContainer").classList.add("hide"),loading.hide()}(view,responses[0],responses[1],responses[2])}),ApiClient.getNamedConfiguration("branding").then(function(config){currentBrandingOptions=config,view.querySelector("#txtLoginDisclaimer").value=config.LoginDisclaimer||"",view.querySelector("#txtCustomCss").value=config.CustomCss||""})})}});