define(["require","dialogHelper","layoutManager","globalize","userSettings","emby-checkbox","emby-input","paper-icon-button-light","emby-select","material-icons","formDialogStyle","emby-button","emby-linkbutton","flexStyles"],function(require,dialogHelper,layoutManager,globalize,userSettings){"use strict";function onSubmit(e){return e.preventDefault(),!1}function setFieldValues(context,settings){for(var elems=context.querySelectorAll(".viewSetting-checkboxContainer"),i=0,length=elems.length;i<length;i++)elems[i].querySelector("input").checked=settings[elems[i].getAttribute("data-settingname")]||!1;context.querySelector(".selectImageType").value=settings.imageType||"primary",function(context,settings){for(var elems=context.querySelectorAll(".chkField"),fields=settings.fields||[],i=0,length=elems.length;i<length;i++)elems[i].checked=fields.includes(elems[i].closest(".viewField").getAttribute("data-field"))}(context,settings)}function saveValues(context,settingsKey){for(var elems=context.querySelectorAll(".viewSetting-checkboxContainer"),i=0,length=elems.length;i<length;i++)userSettings.set(settingsKey+"-"+elems[i].getAttribute("data-settingname"),elems[i].querySelector("input").checked);userSettings.set(settingsKey+"-imageType",context.querySelector(".selectImageType").value),function(context,settingsKey){for(var elems=context.querySelectorAll(".chkField:checked"),fields=[],i=0,length=elems.length;i<length;i++)fields.push(elems[i].closest(".viewField").getAttribute("data-field"));fields.length||fields.push("None"),userSettings.set(settingsKey+"-fields",fields.join(","))}(context,settingsKey)}function ViewSettings(){}return ViewSettings.prototype.show=function(options){return require(["text!./viewsettings.template.html"]).then(function(responses){var template=responses[0],dialogOptions={removeOnClose:!0,scrollY:!1};layoutManager.tv?dialogOptions.size="fullscreen":dialogOptions.size="small";var dlg=dialogHelper.createDialog(dialogOptions);dlg.classList.add("formDialog");var submitted,html="";return html+='<div class="formDialogHeader">',html+='<button is="paper-icon-button-light" class="btnCancel hide-mouse-idle-tv" tabindex="-1"><i class="md-icon">&#xE5C4;</i></button>',html+='<h3 class="formDialogHeaderTitle">${Settings}</h3>',html+="</div>",html+=template,dlg.innerHTML=globalize.translateDocument(html,"sharedcomponents"),function(context,options){context.querySelector("form").addEventListener("submit",onSubmit);for(var visibleSettings=options.visibleSettings.settings||[],settingElements=context.querySelectorAll(".viewSetting"),i=0,length=settingElements.length;i<length;i++)visibleSettings.includes(settingElements[i].getAttribute("data-settingname"))?settingElements[i].classList.remove("hide"):settingElements[i].classList.add("hide")}(dlg,options),setFieldValues(dlg,options.settings),dlg.querySelector(".selectImageType").addEventListener("change",function(){!function(context,visibilityOptions,currentViewType){for(var anyVisible,visibleFieldNames=visibilityOptions.fields||[],fields=context.querySelectorAll(".viewField"),i=0,length=fields.length;i<length;i++){var field=fields[i],hideFromViewTypes=field.getAttribute("data-excludeviewtype").split(","),fieldName=field.getAttribute("data-field");hideFromViewTypes.includes(currentViewType)||!visibleFieldNames.includes(fieldName)?field.classList.add("hide"):(field.classList.remove("hide"),anyVisible=!0)}var container=context.querySelector(".showFieldsSection");anyVisible?container.classList.remove("hide"):container.classList.add("hide")}(dlg,options.visibleSettings,this.value)}),dlg.querySelector(".btnCancel").addEventListener("click",function(){dialogHelper.close(dlg)}),dlg.querySelector(".selectImageType").dispatchEvent(new CustomEvent("change",{})),dlg.querySelector("form").addEventListener("change",function(){submitted=!0},!0),dialogHelper.open(dlg).then(function(){return submitted?(saveValues(dlg,options.settingsKey),Promise.resolve()):Promise.reject()})})},ViewSettings});