import BaseTab from"./../modules/tabbedview/basesettingstab.js";import loading from"./../modules/loading/loading.js";import globalize from"./../modules/common/globalize.js";import"./../modules/emby-elements/emby-input/emby-input.js";import"./../modules/emby-elements/emby-button/emby-button.js";import"./../modules/emby-elements/emby-checkbox/emby-checkbox.js";import"./../modules/emby-elements/emby-select/emby-select.js";import formHelper from"./../modules/common/responsehelper.js";function showAlert(options){return Emby.importModule("./modules/common/dialogs/alert.js").then(function(alert){return alert(options)})}function populateLanguages(select,apiClient){return apiClient.getCultures().then(function(languages){let html="";html+="";for(let i=0,length=languages.length;i"+culture.DisplayName+""}select.innerHTML=html})}function populateCountries(select,apiClient){return apiClient.getCountries().then(function(allCountries){let html="";html+="";for(let i=0,length=allCountries.length;i"+culture.DisplayName+""}select.innerHTML=html})}function loadPage(page,config,systemInfo){let metadataPath=config.MetadataPath||"";metadataPath=metadataPath||systemInfo.InternalMetadataPath,page.querySelector(".txtMetadataPath").value=metadataPath,page.querySelector(".txtMetadataNetworkPath").value=config.MetadataNetworkPath||"",page.querySelector(".chkExternalContentInSuggestions").checked=config.EnableExternalContentInSuggestions,page.querySelector(".chkPeopleMetadata").checked=config.EnableSavedMetadataForPeople,page.querySelector(".selectLanguage").value=config.PreferredMetadataLanguage||"",page.querySelector(".selectCountry").value=config.MetadataCountryCode||"",loading.hide()}function loadMetadataConfig(page,config){page.querySelector(".selectDateAdded").value=config.UseFileCreationTimeForDateAdded?"1":"0"}function saveMetadata(form,apiClient){apiClient.getNamedConfiguration("metadata").then(function(config){config.UseFileCreationTimeForDateAdded="1"===form.querySelector(".selectDateAdded").value,apiClient.updateNamedConfiguration("metadata",config)})}function onSubmitFail(response){loading.hide(),response&&404===response.status?showAlert("The metadata path entered could not be found. Please ensure the path is valid and try again."):response&&500===response.status&&showAlert("The metadata path entered is not valid. Please ensure the path exists and that Emby server has write access to the folder.")}function onSubmit(e){loading.show();let form=e.target,apiClient=this.getApiClient();return apiClient.getServerConfiguration().then(function(config){config.PreferredMetadataLanguage=form.querySelector(".selectLanguage").value,config.MetadataCountryCode=form.querySelector(".selectCountry").value,config.MetadataPath=form.querySelector(".txtMetadataPath").value,config.MetadataNetworkPath=form.querySelector(".txtMetadataNetworkPath").value,config.EnableExternalContentInSuggestions=form.querySelector(".chkExternalContentInSuggestions").checked,config.EnableSavedMetadataForPeople=form.querySelector(".chkPeopleMetadata").checked,apiClient.updateServerConfiguration(config).then(formHelper.handleConfigurationSavedResponse,onSubmitFail)}),saveMetadata(form,apiClient),e.preventDefault(),e.stopPropagation(),!1}function View(view,params){BaseTab.apply(this,arguments)}Object.assign(View.prototype,BaseTab.prototype),View.prototype.onTemplateLoaded=function(){BaseTab.prototype.onTemplateLoaded.apply(this,arguments);let view=this.view;view.querySelector(".metadataPathDescription").innerHTML=globalize.translate("LabelMetadataPathHelp",'',""),view.querySelector(".btnSelectMetadataPath").addEventListener("click",function(){Emby.importModule("./modules/directorybrowser/directorybrowser.js").then(function(directoryBrowser){let picker=new directoryBrowser;picker.show({path:view.querySelector(".txtMetadataPath").value,networkSharePath:view.querySelector(".txtMetadataNetworkPath").value,callback:function(path,networkPath){path&&(view.querySelector(".txtMetadataPath").value=path,view.querySelector(".txtMetadataNetworkPath").value=networkPath),picker.close()},validateWriteable:!0,header:globalize.translate("HeaderSelectMetadataPath"),instruction:globalize.translate("HeaderSelectMetadataPathHelp"),enableNetworkSharePath:!0})})}),view.querySelector("form").addEventListener("submit",onSubmit.bind(this))},View.prototype.loadSettingsInternal=function(){let view=this.view;var apiClient=this.getApiClient();return apiClient.isMinServerVersion("4.8.0.54")?view.querySelector(".fldPeopleMetadata").classList.remove("hide"):view.querySelector(".fldPeopleMetadata").classList.add("hide"),Promise.all([apiClient.getServerConfiguration(),populateLanguages(view.querySelector(".selectLanguage"),apiClient),populateCountries(view.querySelector(".selectCountry"),apiClient),apiClient.getSystemInfo(),apiClient.getNamedConfiguration("metadata")]).then(function(responses){var systemInfo=responses[3];loadPage(view,responses[0],systemInfo),loadMetadataConfig(view,responses[4])})},View.prototype.loadTemplate=function(){return require(["text!librarysetup/advancedtab.html"])};export default View;