import{slicedToArray as e}from"../../../_virtual/_rollupPluginBabelHelpers.js";import{jsx as i}from"react/jsx-runtime";import r,{forwardRef as n,useRef as o,useState as t,useEffect as s,useMemo as a,useCallback as l}from"react";import u from"classnames";import c from"../../../hooks/useGridKeyboardNavigation/useGridKeyboardNavigation.js";import d from"../../../hooks/useMergeRefs.js";import m from"../../../hooks/usePrevious/index.js";import{NOOP as f}from"../../../utils/function-utils.js";import"./TabList.scss.js";import{TabSize as v}from"../Tab/TabConstants.js";var p=n((function(n,p){var b=n.className,h=n.id,g=n.onTabChange,j=void 0===g?f:g,C=n.activeTabId,I=void 0===C?0:C,T=n.tabType,x=void 0===T?"Compact":T,k=n.size,y=void 0===k?v.LARGE:k,N=n.children,A=o(null),L=d({refs:[p,A]}),O=t(I),E=e(O,2),G=E[0],w=E[1],z=m(I);s((function(){I!==z&&I!==G&&w(I)}),[I,z,G,w]);var B=a((function(){var e=new Set;return r.Children.forEach(N,(function(i,r){i.props.disabled&&e.add(r)})),e}),[N]),K=l((function(e){B.has(e)||(w(e),j&&j(e))}),[j,B]),P=l((function(e,i){var r,n=null===(r=N[i].props)||void 0===r?void 0:r.onClick;B.has(i)||(n&&n(i),K(i))}),[N,B,K]),R=l((function(e){return N[e]}),[N]),S=a((function(){return Array.from(B)}),[B]),_=o(),H=c({ref:_,numberOfItemsInLine:null==N?void 0:N.length,itemsCount:null==N?void 0:N.length,getItemByIndex:R,onItemClicked:P,disabledIndexes:S}),M=H.activeIndex,q=H.onSelectionAction,D=a((function(){return r.Children.map(N,(function(e,i){return r.cloneElement(e,{value:i,active:G===i,focus:M===i,onClick:q,size:y})}))}),[N,G,M,q,y]);return i("div",Object.assign({ref:L,className:u("tabs--wrapper",b,x),id:h},{children:i("ul",Object.assign({ref:_,tabIndex:0,className:u("tabs-list",y),role:"tablist"},{children:D}))}))}));Object.assign(p,{isTabList:!0});var b=p;export{b as default};
