"use strict";var core=require("@gem-sdk/core"),React=require("react");const useTabInteraction=({activeKey:e,setActiveKey:t,activeTab:r,refContainer:a,componentUid:n})=>{let{trigger:c,onListener:i,interactionListenerLoaded:u,saveToElementInteractionData:o,findElementIncludingSelf:d}=core.useInteraction(),s=core.useEditorMode(),l=r=>{let{data:a,isRollback:n,element:c,key:i}=r||{};if(void 0===a&&n)return;let u=Number(a)+1;if(n){t(u);return}o(c,i,String(e)),t(u)},b=e=>{c({event:"gp:rollback:tab-active",selector:`[data-id="${n}"]`,element:a.current}),c({event:"gp:tab-active",selector:`[data-id="${n}"]`,data:e,element:a.current})};return React.useEffect(()=>{if("edit"===s)return;u(()=>{b(r-1)});let e=`[data-id="${n}"]`,t=d(document,e),a=i({event:"gp:change-open-tab",selector:e},e=>{l({...e,element:t,key:e?.uniqueStorageKey})});return()=>{a?.()}},[]),{dispatchEventTabActive:b}};exports.useTabInteraction=useTabInteraction;
