import{getContext as e,getElement as t,store as r}from"@wordpress/interactivity";function n(e){return!!e&&(!1===e.allowMultiple?Number(e.currentItem)===Number(e.itemId):!0===e.isOpen)}r("blocksify/accordion",{state:{get isItemOpen(){return n(e())},get itemAriaExpanded(){return n(e())?"true":"false"},get itemHidden(){return!n(e())}},actions:{toggle(t){if(t&&t.target&&t.target.closest&&t.target.closest(".bsy-accordion__body"))return;const r=e();r&&(!1!==r.allowMultiple?r.isOpen=!r.isOpen:r.currentItem=Number(r.currentItem)===Number(r.itemId)?null:Number(r.itemId))}},callbacks:{onKeydown(r){const n=r.key;if("Enter"===n||" "===n){const n=t().ref;if(r.target!==n)return;r.preventDefault();const o=e();if(!o)return;return void(!1===o.allowMultiple?o.currentItem=Number(o.currentItem)===Number(o.itemId)?null:Number(o.itemId):o.isOpen=!o.isOpen)}if("ArrowUp"!==n&&"ArrowDown"!==n&&"Home"!==n&&"End"!==n)return;r.preventDefault();const o=t().ref,i=o.closest('[data-wp-interactive="blocksify/accordion"]');if(!i)return;const c=Array.from(i.querySelectorAll(":scope > .bsy-accordion__item")),l=c.indexOf(o);let s=l;"ArrowDown"===n?s=(l+1)%c.length:"ArrowUp"===n?s=(l-1+c.length)%c.length:"Home"===n?s=0:"End"===n&&(s=c.length-1);const u=c[s];u&&"function"==typeof u.focus&&u.focus()}}});