(()=>{const e=()=>{if(window.location.hash)return;const e=new URL(window.location.href).searchParams;let t="";if(e.forEach((e,o)=>{if(t||!String(e).trim())return;const r=o.match(/^ui_tax\[([^\]]+)\]$/);r&&(t=r[1])}),!t)return;const o=document.querySelector(`.wp-block-uicore-filters-terms[data-tax="${t}"]`);if(!o)return;const r=()=>o.scrollIntoView({behavior:"auto",block:"start"});requestAnimationFrame(r),setTimeout(r,120)};document.addEventListener("DOMContentLoaded",()=>{window.addEventListener("load",e,{once:!0}),document.querySelectorAll("select.choices[data-tax]").forEach(e=>{const t="undefined"!=typeof globalThis?globalThis.Choices:null;if(t&&!e.__uicoreChoices)try{const o=e.parentElement?.querySelector(".uicore-filters-term-template");e.__uicoreTermTemplateHtml=e.dataset.termMarkup||o?.innerHTML||"";const r=!(!e.multiple&&"1"!==e.dataset.multiSelect),c="string"==typeof e.dataset.placeholderText&&""!==e.dataset.placeholderText.trim()?e.dataset.placeholderText:"Select item",a=r,i="1"===e.dataset.hasActive,s=(e.dataset.termsBlockClass?.trim()||"").split(/\s+/).filter(Boolean),l=[...s,"uicore-is-active"],n=e.dataset.termItemClass?.trim()||"",d=["wp-block-uicore-filters-terms-item",...n?n.split(/\s+/).filter(Boolean):[]],u=()=>requestAnimationFrame(()=>(e=>{if(!e)return;const t=e.closest(".choices"),o=t&&t!==e?t:e.parentElement?.closest(".choices");if(!o)return;const r=new Map(Array.from(e.options).map(e=>[e.value,e]));o.querySelectorAll(".choices__item").forEach(t=>{var o;const c=null!==(o=t.dataset.value)&&void 0!==o?o:"",a=r.get(c),i=!!t.closest(".choices__list--single, .choices__list--multiple"),s=t.classList.contains("is-selected")||"true"===t.getAttribute("aria-selected")||t.hasAttribute("data-item"),l=i&&s;if(t.classList.toggle("uicore-is-active",l),t.querySelectorAll('[class*="wp-block-uicore-"]').forEach(e=>{e.classList.toggle("uicore-is-active",l)}),!a)return;const n=a.dataset.termName||a.textContent||"",d=a.dataset.termCount||"",u=e.__uicoreTermTemplateHtml||"",m=""!==d&&"1"!==a.dataset.termIsAll;if(t.querySelector(".wp-block-uicore-filters-term-name")&&(!t.hasAttribute("data-deletable")||t.querySelector(".choices__button")))return;const h=t.querySelector(".choices__button");if(t.textContent="",""!==u.trim()){const e=document.createElement("template");e.innerHTML=u;const o=e.content.firstElementChild;if(o){Array.from(o.childNodes).forEach(e=>{t.appendChild(e.cloneNode(!0))});const e=t.querySelector(".wp-block-uicore-filters-term-name");e&&(e.textContent=n);const r=t.querySelector(".wp-block-uicore-filters-term-count");return r&&(m?r.textContent=` ${d}`:r.remove()),h&&t.appendChild(h),void t.querySelectorAll('[class*="wp-block-uicore-"]').forEach(e=>{e.classList.toggle("uicore-is-active",l)})}}const p=document.createElement("span");if(p.className="wp-block-uicore-filters-term-name",p.textContent=n,t.appendChild(p),m){const e=document.createElement("span");e.className="wp-block-uicore-filters-term-count",e.textContent=` ${d}`,t.appendChild(e)}h&&t.appendChild(h),t.querySelectorAll('[class*="wp-block-uicore-"]').forEach(e=>{e.classList.toggle("uicore-is-active",l)})})})(e));if(r||i||(e.selectedIndex=-1,Array.from(e.options).forEach(e=>{e.selected=!1})),e.__uicoreChoices=new t(e,{allowHTML:!1,shouldSort:!1,searchEnabled:r,searchChoices:r,searchFloor:r?0:9999,searchResultLimit:20,itemSelectText:"",removeItemButton:r,closeDropdownOnSelect:!r&&"auto",renderSelectedChoices:r?"always":"auto",placeholderValue:a?c:"",searchPlaceholderValue:a?c:"",placeholder:a,classNames:{containerOuter:["choices"],containerInner:["choices__inner",...s],list:["choices__list"],listDropdown:["choices__list--dropdown",...l],item:["choices__item",...d],itemChoice:["choices__item--choice",...r?[]:d]}}),r){const t=e.parentElement?.closest(".choices"),o=t?.querySelector(".choices__input--cloned");o&&o.setAttribute("placeholder",c)}u(),e.addEventListener("change",u)}catch(t){e.__uicoreChoices=null}const o=()=>{requestAnimationFrame(()=>{const t=e.dataset.tax,o=e.dataset.queryId,r=e.multiple||"1"===e.dataset.multiSelect?Array.from(e.selectedOptions):Array.from(e.options).filter(e=>e.selected),c=r.some(e=>"1"===e.dataset.termIsAll||""===e.value||"0"===e.value)?"":r.map(e=>e.value).filter(Boolean).join(","),a=new URL(window.location.href),{searchParams:i}=a;(e=>{const t=[];e.forEach((e,o)=>{("paged"===o||"query-page"===o||/^query-\d+-page$/.test(o))&&t.push(o)}),t.forEach(t=>e.delete(t))})(i),i.delete("ui_tax"),c?(i.set(`ui_tax[${t}]`,c),o&&i.set("ui_qid",o)):(i.delete(`ui_tax[${t}]`),(e=>{let t=!1;return e.forEach((e,o)=>{!t&&String(e).trim()&&/^ui_tax\[([^\]]+)\]$/.test(o)&&(t=!0)}),t})(i)||i.delete("ui_qid"));const s=a.toString();s!==window.location.href&&(window.location.href=s)})};e.addEventListener("change",o),e.addEventListener("removeItem",o),e.addEventListener("addItem",o)})})})();