define(["loading","dom","appRouter","emby-select"],function(loading,dom,appRouter){"use strict";function onCountryChange(){var country=this.value,fldGuideProvider=dom.parentWithTag(this,"FORM").querySelector(".fldGuideProvider");country?fldGuideProvider.classList.remove("hide"):(fldGuideProvider.classList.add("hide"),loading.hide());var selectProvider=fldGuideProvider.querySelector(".selectProvider");selectProvider.innerHTML="",country&&(loading.show(),ApiClient.getJSON(ApiClient.getUrl("LiveTv/ListingProviders/Available",{Country:country})).then(function(options){!function(select,options){select.innerHTML='<option value=""></option>'+options.map(function(o){return'<option data-url="'+o.SetupUrl+'" value="'+o.Id+'">'+o.Name+"</option>"}).join("")}(selectProvider,options),loading.hide()}))}function cancel(){appRouter.back()}function onSubmit(e){var selectProvider=this.querySelector(".selectProvider"),country=this.querySelector(".selectCountry").value;Dashboard.navigate(selectProvider.options[selectProvider.selectedIndex].getAttribute("data-url")+"?country="+country),e.preventDefault(),e.stopPropagation()}return function(view,params){view.querySelector("form").addEventListener("submit",onSubmit),view.querySelector(".btnCancel").addEventListener("click",cancel);var selectCountry=view.querySelector(".selectCountry");!function(select){ApiClient.getCountries().then(function(allCountries){var html="";html+="<option value=''></option>";for(var i=0,length=allCountries.length;i<length;i++){var culture=allCountries[i];html+="<option value='"+culture.ThreeLetterISORegionName+"'>"+culture.DisplayName+"</option>"}select.innerHTML=html})}(selectCountry),selectCountry.addEventListener("change",onCountryChange)}});