import*as e from"@wordpress/interactivity";var t,n,r={d:function(e,t){for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},o:function(e,t){return Object.prototype.hasOwnProperty.call(e,t)}},o=(t={getContext:function(){return e.getContext},getElement:function(){return e.getElement},store:function(){return e.store}},n={},r.d(n,t),n);const{actions:i}=(0,o.store)("surecart/dropdown",{state:{get isMenuItemFocused(){const e=(0,o.getContext)(),t=(0,o.getElement)();return e.activeMenuItemId===t.attributes.id}},actions:{toggleMenu:e=>{e.preventDefault();const t=(0,o.getContext)();t.isMenuOpen=!t.isMenuOpen},selectItem:()=>{const e=(0,o.getContext)();(0,o.getElement)().ref.querySelector("#"+e.activeMenuItemId).click()},menuKeyUp:e=>{const t=(0,o.getContext)(),n=(0,o.getElement)().ref.querySelectorAll('[role="menuitem"]');if("Escape"===e.key&&(e.preventDefault(),t.isMenuOpen=!1),"Enter"===e.key){if(e.preventDefault(),!t.isMenuOpen)return t.isMenuOpen=!0,t.index=0,void(t.activeMenuItemId=n?.[0]?.attributes?.id?.value);i.selectItem(e)}if("ArrowDown"===e.key||"ArrowUp"===e.key){if(e.preventDefault(),!t.isMenuOpen)return t.isMenuOpen=!0,t.index=0,void(t.activeMenuItemId=n?.[0]?.attributes?.id?.value);const r="ArrowDown"===e.key;t.index=r?Math.min(t.index+1,n?.length-1):Math.max(t.index-1,0),t.activeMenuItemId=n[t.index].attributes.id.value}},menuKeyDown:e=>{["ArrowDown","ArrowUp","Enter","Escape"].includes(e.key)&&e.preventDefault()}},callbacks:{maybeCloseMenu:e=>{const t=(0,o.getContext)(),{ref:n}=(0,o.getElement)();"Escape"!==e?.key&&n.contains(e.target)||(t.isMenuOpen=!1)}}});