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)}},i=(t={getContext:function(){return e.getContext},getElement:function(){return e.getElement},store:function(){return e.store},withSyncEvent:function(){return e.withSyncEvent}},n={},r.d(n,t),n);const{actions:o}=(0,i.store)("surecart/dropdown",{state:{get isMenuItemFocused(){const e=(0,i.getContext)(),t=(0,i.getElement)();return e.activeMenuItemId===t.attributes.id}},actions:{toggleMenu:(0,i.withSyncEvent)((e=>{e.preventDefault();const t=(0,i.getContext)();t.isMenuOpen=!t.isMenuOpen})),selectItem:()=>{const e=(0,i.getContext)();(0,i.getElement)().ref.querySelector("#"+e.activeMenuItemId).click()},menuKeyUp:(0,i.withSyncEvent)((e=>{const t=(0,i.getContext)(),n=(0,i.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);o.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:(0,i.withSyncEvent)((e=>{["ArrowDown","ArrowUp","Enter","Escape"].includes(e.key)&&e.preventDefault()}))},callbacks:{maybeCloseMenu:e=>{const t=(0,i.getContext)(),{ref:n}=(0,i.getElement)();"Escape"!==e?.key&&n.contains(e.target)||(t.isMenuOpen=!1)}}});