import*as e from"@wordpress/interactivity";var t={d:(e,r)=>{for(var s in r)t.o(r,s)&&!t.o(e,s)&&Object.defineProperty(e,s,{enumerable:!0,get:r[s]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};const r=(s={getElement:()=>e.getElement,store:()=>e.store},n={},t.d(n,s),n);var s,n;const{actions:o}=(0,r.store)("gatherpress",{actions:{preventDefault(e){e&&e.preventDefault()},linkHandler(e){o.preventDefault(e);const t=(0,r.getElement)(),s=t.ref.closest(".wp-block-gatherpress-dropdown");if("select"===s?.dataset.dropdownMode){const e=s.querySelector(".wp-block-gatherpress-dropdown__menu"),r=s.querySelector(".wp-block-gatherpress-dropdown__trigger"),n=t.ref.closest(".wp-block-gatherpress-dropdown-item");if(n){const t=n.querySelector("a");if(t?.classList.contains("gatherpress--is-disabled"))return;t&&(t.classList.add("gatherpress--is-disabled"),t.setAttribute("tabindex","-1"),t.setAttribute("aira-disabled","true")),e.querySelectorAll(".wp-block-gatherpress-dropdown-item").forEach(e=>{const t=e.querySelector("a");t&&e!==n&&(t.classList.remove("gatherpress--is-disabled"),t.removeAttribute("tabindex"),t.removeAttribute("aria-disabled"))}),r&&t&&(r.textContent=t.textContent.trim()),e&&(e.classList.remove("gatherpress--is-visible"),r.setAttribute("aria-expanded","false"),r.focus())}}},toggleDropdown(e=null,t=null,s=!1){o.preventDefault(e);const n=(t=null!=t?t:(0,r.getElement)()).ref.parentElement.querySelector(".wp-block-gatherpress-dropdown__menu"),a=t.ref.parentElement.querySelector(".wp-block-gatherpress-dropdown__trigger");if(!n||!a)return;let l=!1;s?n.classList.remove("gatherpress--is-visible"):l=n.classList.toggle("gatherpress--is-visible"),a.setAttribute("aria-expanded",l?"true":"false");const c=[a,...n.querySelectorAll(["a[href]:not(.gatherpress--is-disabled)"].join(","))];l?(a.focus(),"function"==typeof t.ref.cleanupFocusTrap&&t.ref.cleanupFocusTrap(),t.ref.cleanupFocusTrap=function(e){if(!e||0===e.length)return()=>{};const t=e.filter(e=>null!==e.offsetParent&&"hidden"!==window.getComputedStyle(e).visibility&&"0"!==window.getComputedStyle(e).opacity);if(0===t.length)return()=>{};const r=t[0],s=t.at(-1),n=e=>{"Tab"===e.key&&(e.shiftKey&&r.ownerDocument.activeElement===r?(e.preventDefault(),s.focus()):e.shiftKey||s.ownerDocument.activeElement!==s||(e.preventDefault(),r.focus()))},o=e=>{"Escape"===e.key&&a()},a=()=>{document.removeEventListener("keydown",n),document.removeEventListener("keydown",o)};return document.addEventListener("keydown",n),document.addEventListener("keydown",o),a}(c),"function"==typeof t.ref.cleanupCloseHandlers&&t.ref.cleanupCloseHandlers(),t.ref.cleanupCloseHandlers=function(e,t,r){const s=e=>{e.classList.remove("gatherpress--is-visible"),r()},n=t=>{"Escape"===t.key&&document.querySelectorAll(`${e}.gatherpress--is-visible`).forEach(e=>s(e))},o=t=>{document.querySelectorAll(`${e}.gatherpress--is-visible`).forEach(e=>{e.parentElement.contains(t.target)||s(e)})};return document.addEventListener("keydown",n),document.addEventListener("click",o),()=>{document.removeEventListener("keydown",n),document.removeEventListener("click",o)}}(".wp-block-gatherpress-dropdown__menu",0,()=>{"function"==typeof t.ref.cleanupFocusTrap&&t.ref.cleanupFocusTrap(),o.toggleDropdown(null,t,!0)})):("function"==typeof t.ref.cleanupFocusTrap&&t.ref.cleanupFocusTrap(),"function"==typeof t.ref.cleanupCloseHandlers&&t.ref.cleanupCloseHandlers(),a.focus())}}});