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