import{getContext as t,getElement as e,store as r}from"@wordpress/interactivity";function l(t){const e=t.scrollWidth>t.clientWidth+1,r=t.scrollHeight>t.clientHeight+1;t.classList.toggle("is-fade-left",e&&t.scrollLeft>1),t.classList.toggle("is-fade-right",e&&t.scrollLeft<t.scrollWidth-t.clientWidth-1),t.classList.toggle("is-fade-top",r&&t.scrollTop>1),t.classList.toggle("is-fade-bottom",r&&t.scrollTop<t.scrollHeight-t.clientHeight-1)}function n(t,e){if(!t)return;const r=Array.from(t.querySelectorAll(".bsy-tabs__tab")),n=t.getBoundingClientRect();if(e>0){const e=r.find(t=>t.getBoundingClientRect().right>n.right+1);e&&(t.scrollLeft+=e.getBoundingClientRect().right-n.right)}else{let e=null;for(let t=r.length-1;t>=0;t--)if(r[t].getBoundingClientRect().left<n.left-1){e=r[t];break}e&&(t.scrollLeft+=e.getBoundingClientRect().left-n.left)}l(t)}function o(t,e){t.querySelectorAll('[role="tab"]').forEach((t,r)=>{t.setAttribute("tabindex",r===e?"0":"-1")})}function s(t,e){const r=t.querySelectorAll('[role="tab"]')[e];r&&"function"==typeof r.scrollIntoView&&r.scrollIntoView({behavior:"instant",inline:"nearest",block:"nearest"})}function i(t){if(!t)return null;const e=t.closest('[class*="bsy-tabs-"]');return e?e.querySelector(":scope > .bsy-tabs__tablist"):null}r("blocksify/tabs",{state:{get tabs(){const e=t(),r=Math.max(0,e?.tabCount||0),l=e?.activeIndex||0;return Array.from({length:r},(t,e)=>({isActive:e===l,ariaSelected:e===l?"true":"false"}))}},actions:{activate(){const r=t(),l=e().ref;if(!l)return;const n=parseInt(l.dataset.tabIndex,10);if(Number.isNaN(n))return;r.activeIndex=n;const i=l.closest('[role="tablist"]');i&&(o(i,n),s(i,n)),l.focus()},carouselPrev(){n(i(e().ref),-1)},carouselNext(){n(i(e().ref),1)}},callbacks:{initFade(){const t=e().ref;t&&l(t)},updateFade(){const t=e().ref;t&&l(t)},onKeydown(r){const l=t(),n=e().ref;if(!n)return;const i=n.closest('[role="tablist"]');if(!i)return;const c="vertical"!==(i.getAttribute("aria-orientation")||"horizontal"),a=Array.from(i.querySelectorAll('[role="tab"]')),f=a.indexOf(n);if(-1===f)return;let u=-1;switch(r.key){case"ArrowLeft":c&&(u=f>0?f-1:a.length-1);break;case"ArrowRight":c&&(u=(f+1)%a.length);break;case"ArrowUp":c||(u=f>0?f-1:a.length-1);break;case"ArrowDown":c||(u=(f+1)%a.length);break;case"Home":u=0;break;case"End":u=a.length-1;break;default:return}if(-1===u)return;r.preventDefault(),l.activeIndex=u,o(i,u),s(i,u);const g=a[u];g&&g.focus()}}});