define(["jQuery","loading","libraryMenu","globalize","fnchecked","emby-checkbox","emby-linkbutton"],function($,loading,libraryMenu,globalize){"use strict";function loadPage(page,config){config.MergeMetadataAndImagesByName?$(".fldImagesByName",page).hide():$(".fldImagesByName",page).show(),$("#chkSaveMetadataHidden",page).checked(config.SaveMetadataHidden),$("#txtMetadataPath",page).val(config.MetadataPath||""),$("#txtMetadataNetworkPath",page).val(config.MetadataNetworkPath||""),loading.hide()}function loadMetadataConfig(page,config){$("#selectDateAdded",page).val(config.UseFileCreationTimeForDateAdded?"1":"0")}function saveMetadata(form){ApiClient.getNamedConfiguration("metadata").then(function(config){config.UseFileCreationTimeForDateAdded="1"===$("#selectDateAdded",form).val(),ApiClient.updateNamedConfiguration("metadata",config)})}function alertText(options){require(["alert"],function(alert){alert(options)})}function onSubmitFail(response){loading.hide(),response&&404===response.status?alertText("The metadata path entered could not be found. Please ensure the path is valid and try again."):response&&500===response.status&&alertText("The metadata path entered is not valid. Please ensure the path exists and that Emby server has write access to the folder.")}function onSubmit(){loading.show();var form=this;return ApiClient.getServerConfiguration().then(function(config){config.SaveMetadataHidden=$("#chkSaveMetadataHidden",form).checked(),config.EnableTvDbUpdates=$("#chkEnableTvdbUpdates",form).checked(),config.EnableTmdbUpdates=$("#chkEnableTmdbUpdates",form).checked(),config.MetadataPath=$("#txtMetadataPath",form).val(),config.MetadataNetworkPath=$("#txtMetadataNetworkPath",form).val(),ApiClient.updateServerConfiguration(config).then(Dashboard.processServerConfigurationUpdateResult,onSubmitFail)}),saveMetadata(form),!1}function getTabs(){return[{href:"library.html",name:globalize.translate("HeaderLibraries")},{href:"librarydisplay.html",name:globalize.translate("TabDisplay")},{href:"metadataimages.html",name:globalize.translate("TabMetadata")},{href:"librarysettings.html",name:globalize.translate("TabAdvanced")}]}return function(view,params){$("#btnSelectMetadataPath",view).on("click.selectDirectory",function(){require(["directorybrowser"],function(directoryBrowser){var picker=new directoryBrowser;picker.show({path:$("#txtMetadataPath",view).val(),networkSharePath:$("#txtMetadataNetworkPath",view).val(),callback:function(path,networkPath){path&&($("#txtMetadataPath",view).val(path),$("#txtMetadataNetworkPath",view).val(networkPath)),picker.close()},validateWriteable:!0,header:globalize.translate("HeaderSelectMetadataPath"),instruction:globalize.translate("HeaderSelectMetadataPathHelp"),enableNetworkSharePath:!0})})}),$(".librarySettingsForm").off("submit",onSubmit).on("submit",onSubmit),view.addEventListener("viewshow",function(){libraryMenu.setTabs("librarysetup",4,getTabs),loading.show();var page=this;ApiClient.getServerConfiguration().then(function(config){loadPage(page,config)}),ApiClient.getNamedConfiguration("metadata").then(function(metadata){loadMetadataConfig(page,metadata)}),ApiClient.getSystemInfo().then(function(info){"Windows"===info.OperatingSystem?page.querySelector(".fldSaveMetadataHidden").classList.remove("hide"):page.querySelector(".fldSaveMetadataHidden").classList.add("hide")})})}});