import{slicedToArray as t}from"../../_virtual/_rollupPluginBabelHelpers.js";import{jsx as o,jsxs as e}from"react/jsx-runtime";import{forwardRef as i,useRef as r,useState as a,useCallback as n,useMemo as s,useEffect as l}from"react";import c from"classnames";import u from"../Button/Button.js";import p from"../../hooks/usePrevious/index.js";import m from"../../hooks/useMergeRefs.js";import{backwardCompatibilityForProperties as d}from"../../helpers/backwardCompatibilityForProperties.js";import{baseClassName as f}from"./ButtonGroupConstants.js";import{ButtonWrapper as v}from"./ButtonWrapper.js";import"./ButtonGroup.scss.js";import{BASE_SIZES as b}from"../../constants/sizes.js";var j=i((function(i,u){var j=i.options,h=i.name,g=void 0===h?"":h,C=i.disabled,x=void 0!==C&&C,y=i.value,B=void 0===y?"":y,_=i.onSelect,N=i.size,k=void 0===N?b.MEDIUM:N,z=i.groupAriaLabel,D=void 0===z?"":z,M=i.tooltipPosition,P=i.tooltipHideDelay,S=i.tooltipShowDelay,I=i.tooltipContainerSelector,O=i.tooltipMoveBy,w=d([i.className,i.componentClassName]),A=r(),F=a(B),H=t(F,2),L=H[0],T=H[1],G=p(B),E=m({refs:[u,A]}),R=n((function(t){x||t.disabled||(T(t.value),_&&_(t.value,g))}),[_,x,g]),U=s((function(){return j.find((function(t){return t.value===L}))}),[j,L]),W=s((function(){return j.map((function(t,e){var i=t.value===L;return o(v,Object.assign({size:k,onClick:function(){return R(t)},rightIcon:t.icon,leftIcon:t.leftIcon,active:i,rightFlat:e!==j.length-1,leftFlat:0!==e,preventClickAnimation:!0,ariaLabel:t.ariaLabel,tooltipContent:t.tooltipContent,tooltipPosition:M,tooltipHideDelay:P,tooltipShowDelay:S,tooltipContainerSelector:I,tooltipMoveBy:O,className:c("".concat(f,"__option-text"),{selected:i,disabled:x,"button-disabled":t.disabled})},{children:t.text}),t.value)}))}),[j,x,R,k,L,M,P,S,I,O]);return l((function(){B!==G&&B!==L&&T(B)}),[B,G,L,T]),e("div",Object.assign({className:c(f,w,{disabled:x}),ref:E},{children:[o("div",Object.assign({role:"group","aria-label":D,className:c("".concat(f,"__buttons-container")),"aria-disabled":x},{children:W})),U&&U.subText&&o("div",Object.assign({className:"".concat(f,"__sub-text-container")},{children:U.subText}))]}))}));j.sizes=u.sizes;var h=j;export{h as default};
