define(["dialogHelper","loading","layoutManager","connectionManager","globalize","emby-input","emby-checkbox","paper-icon-button-light","emby-select","material-icons","formDialogStyle","emby-button","emby-scroller"],function(dialogHelper,loading,layoutManager,connectionManager,globalize){"use strict";function onSubmit(e){loading.show();for(var dlg=function(elem,className){for(;!elem.classList||!elem.classList.contains(className);)if(!(elem=elem.parentNode))return null;return elem}(e.target,"dialog"),options=this.options,replaceAllMetadata="all"===dlg.querySelector("#selectMetadataRefreshMode").value,mode="FullRefresh",replaceAllImages=dlg.querySelector(".chkReplaceImages").checked,i=0,length=options.items.length;i<length;i++){var item=options.items[i];connectionManager.getApiClient(item).refreshItem(item.Id,{Recursive:!0,ImageRefreshMode:mode,MetadataRefreshMode:mode,ReplaceAllImages:replaceAllImages,ReplaceAllMetadata:replaceAllMetadata})}return dialogHelper.close(dlg),require(["toast"],function(toast){toast(globalize.translate("RefreshingMetadataDots"))}),loading.hide(),e.preventDefault(),!1}function RefreshDialog(options){this.options=options}return RefreshDialog.prototype.show=function(){var dialogOptions={removeOnClose:!0,scrollY:!1};layoutManager.tv?dialogOptions.size="fullscreen":dialogOptions.size="small";var dlg=dialogHelper.createDialog(dialogOptions);dlg.classList.add("formDialog");var html="";return html+='<div class="formDialogHeader">',html+='<button is="paper-icon-button-light" class="btnCancel autoSize" tabindex="-1"><i class="md-icon">&#xE5C4;</i></button>',html+='<h3 class="formDialogHeaderTitle">',html+=globalize.translate("HeaderRefreshMetadata"),html+="</h3>",html+="</div>",html+=function(){var html="";return html+='<div is="emby-scroller" data-horizontal="false" data-centerfocus="card" class="formDialogContent">',html+='<div class="scrollSlider">',html+='<form class="dialogContentInner dialog-content-centered padded-left padded-right" style="padding-top:2em;">',html+='<div class="fldSelectPlaylist selectContainer">',html+='<select is="emby-select" id="selectMetadataRefreshMode" label="'+globalize.translate("LabelRefreshMode")+'">',html+='<option value="missing">'+globalize.translate("SearchForMissingMetadata")+"</option>",html+='<option value="all" selected>'+globalize.translate("ReplaceAllMetadata")+"</option>",html+="</select>",html+="</div>",html+='<label class="checkboxContainer hide fldReplaceExistingImages">',html+='<input type="checkbox" is="emby-checkbox" class="chkReplaceImages" />',html+="<span>"+globalize.translate("ReplaceExistingImages")+"</span>",html+="</label>",html+='<div class="fieldDescription">',html+=globalize.translate("RefreshDialogHelp"),html+="</div>",html+="<br />",html+='<div class="formDialogFooter">',html+='<button is="emby-button" type="submit" class="raised btnSubmit block formDialogFooterItem button-submit">'+globalize.translate("Refresh")+"</button>",html+="</div>",html+="</form>",html+="</div>",html+="</div>"}(),dlg.innerHTML=html,dlg.querySelector("form").addEventListener("submit",onSubmit.bind(this)),dlg.querySelector("#selectMetadataRefreshMode").addEventListener("change",function(){dlg.querySelector(".fldReplaceExistingImages").classList.remove("hide")}),this.options.mode&&(dlg.querySelector("#selectMetadataRefreshMode").value=this.options.mode),dlg.querySelector("#selectMetadataRefreshMode").dispatchEvent(new CustomEvent("change")),dlg.querySelector(".btnCancel").addEventListener("click",function(){dialogHelper.close(dlg)}),new Promise(function(resolve,reject){dlg.addEventListener("close",resolve),dialogHelper.open(dlg)})},RefreshDialog});