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