(()=>{if(!document.querySelectorAll('.podcasts-display').length)return;let lastURLToFetch=null;const load_content=(url,scroll=true)=>{document.querySelector('.podcasts-display-content-inner').style.display='none';document.querySelector('.podcasts-display-content-loading').style.display='block';lastURLToFetch=url;fetch(url).then(function(response){return response.text();}).then(function(response){if(lastURLToFetch!==url)return;const parser=new DOMParser();const response_document=parser.parseFromString(response,'text/html');document.querySelector('.podcasts-display-content-inner').innerHTML=response_document.querySelector('.podcasts-display-content-inner').innerHTML;document.querySelector('.podcasts-display-content-inner').style.display='block';document.querySelector('.podcasts-display-content-loading').style.display='none';if(scroll){let distance_from_top=window.scrollY+document.querySelector('.podcasts-display').getBoundingClientRect().top-document.querySelector('.header').offsetHeight;if(document.querySelector('#wpadminbar')){distance_from_top-=document.querySelector('#wpadminbar').offsetHeight;}
window.scrollTo({top:distance_from_top,behavior:'smooth',});}});}
const input_reset=(form)=>{form.querySelectorAll('input[type="checkbox"]').forEach((checkbox)=>{checkbox.checked=false;});}
const process_form=(event)=>{event.preventDefault();const form=event.target.closest('form');const form_data=new FormData(form);const cleaned_url=window.location.href.replaceAll('%5B','[').replaceAll('%5D',']').replace(/ *\[[^\]]*]/g,'[]');const url=new URL(cleaned_url);form.querySelectorAll('[name]').forEach((element)=>{const name=element.attributes.name.value;url.searchParams.delete(name);});for(const entry of form_data.entries()){url.searchParams.append(entry[0],entry[1]);}
const final_url=url.toString();history.pushState(null,null,final_url);load_content(final_url);}
const set_filters=()=>{const cleaned_url=window.location.href.replaceAll('%5B','[').replaceAll('%5D',']').replace(/ *\[[^\]]*]/g,'[]');const url=new URL(cleaned_url);const form=document.querySelector('.podcasts-display').querySelector('form');const form_data=new FormData(form);for(const[key,value]of form_data.entries()){if(key==='paged')continue;form.querySelectorAll(':is(input:not([type="radio"], [type="checkbox"]))[name="'+key+'"]').forEach((input)=>{input.value='';});form.querySelectorAll('input:is([type="radio"], [type="checkbox"])[name="'+key+'"][value="'+value+'"]').forEach((input)=>{input.checked=false;});form.querySelectorAll('select[name="'+key+'"] option[value="'+value+'"]').forEach((option)=>{option.selected=false;});}
for(const[key,value]of url.searchParams.entries()){form.querySelectorAll(':is(input:not([type="radio"], [type="checkbox"]))[name="'+key+'"]').forEach((input)=>{input.value=value;});form.querySelectorAll('input:is([type="radio"], [type="checkbox"])[name="'+key+'"][value="'+value+'"]').forEach((input)=>{input.checked=true;});form.querySelectorAll('select[name="'+key+'"] option[value="'+value+'"]').forEach((option)=>{option.selected=true;});}}
document.addEventListener('click',function(event){if(event.target.matches('.nav-links a, .nav-links a *')){event.preventDefault();const url=event.target.closest('.nav-links a').attributes.href.value;history.pushState(null,null,url);if(scroll){let distance_from_top=window.scrollY+document.querySelector('.podcasts-display').getBoundingClientRect().top-document.querySelector('.header').offsetHeight;if(document.querySelector('#wpadminbar')){distance_from_top-=document.querySelector('#wpadminbar').offsetHeight;}
window.scrollTo({top:distance_from_top,behavior:'smooth',});}
load_content(url,false);}},false);const block=document.querySelector('.podcasts-display');block.querySelectorAll('.podcasts-display-filters-group').forEach((group)=>{group.querySelectorAll('.podcasts-display-filters-group-title').forEach((button)=>{button.addEventListener('click',(event)=>{event.preventDefault();event.target.closest('.podcasts-display-filters-group').classList.toggle('open');});});});block.querySelectorAll('.podcasts-display-filters-group').forEach((group)=>{group.querySelectorAll('.podcasts-display-filters-clear-button').forEach((button)=>{button.addEventListener('click',(event)=>{event.preventDefault();input_reset(button.closest('.podcasts-display-filters-group'));process_form(event);});});});block.querySelectorAll('form').forEach((form)=>{form.addEventListener('submit',process_form);form.addEventListener('change',process_form);});window.onpopstate=history.onpushstate=()=>{load_content(window.location.href);set_filters();};block.querySelector('.podcasts-display-filters-submit').style.display='none';})();