import{slicedToArray as i,toConsumableArray as r}from"../../../_virtual/_rollupPluginBabelHelpers.js";import{jsx as o}from"react/jsx-runtime";import e from"classnames";import n,{forwardRef as t,useRef as a,useState as c,useMemo as s,useCallback as l}from"react";import d from"../../../hooks/useMergeRefs.js";import"./Accordion.scss.js";var u=t((function(t,u){var f=t.children,m=void 0===f?null:f,p=t.allowMultiple,v=void 0!==p&&p,j=t["data-testid"],b=void 0===j?"l3-accordion":j,g=t.defaultIndex,h=void 0===g?[]:g,A=t.className,C=void 0===A?"":A,O=t.id,x=a(null),k=d({refs:[u,x]}),y=c(h),M=i(y,2),N=M[0],_=M[1],w=s((function(){return n.Children.toArray(m)}),[m]),B=l((function(i){return N.includes(i)}),[N]),E=l((function(i){if(v){var o=r(N);if(B(i)){var e=o.indexOf(i);e>-1&&o.splice(e,1)}else o.push(i);_(o)}else _([i])}),[B,N,v]),H=s((function(){return n.Children.map(w,(function(i,r){var o,e,t,a=Object.assign({},null==i?void 0:i.props),c=(o=r,t=O,(e=a).id?e.id:t?"".concat(t,"--item-").concat(o):"".concat("l3-accordion","--item-").concat(o));return n.cloneElement(i,Object.assign(Object.assign({},a),{id:c,onClickAccordionCallback:function(){E(r)},open:B(r)}))}))}),[w,O,B,E]);return o("div",Object.assign({ref:k,className:e("accordion",C),"data-testid":b,id:O},{children:w&&H}))}));export{u as default};
