define(["loading","dom","emby-select"],function(loading,dom){"use strict";function populateCountries(select){return 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})}function renderListingsProviders(select,options){select.innerHTML='<option value=""></option>'+options.map(function(o){return'<option data-url="'+o.SetupUrl+'" value="'+o.Id+'">'+o.Name+"</option>"}).join("")}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){renderListingsProviders(selectProvider,options),loading.hide()}))}function cancel(){history.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");populateCountries(selectCountry),selectCountry.addEventListener("change",onCountryChange)}});