import{slicedToArray as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import{jsx as r}from"react/jsx-runtime";import t,{forwardRef as i,useRef as s,useState as n,useCallback as l,useMemo as o}from"react";import a from"classnames";import c from"../../hooks/useMergeRefs.js";import{VirtualizedListItems as d}from"./VirtualizedListItems/VirtualizedListItems.js";import{keyCodes as m}from"../../constants/keyCodes.js";import"./List.scss.js";var u=i((function(i,u){var f=i.className,y=i.id,p=i.component,v=void 0===p?"ul":p,b=i.children,h=i.dense,j=void 0!==h&&h,g=i.ariaLabel,A=i.ariaDescribedBy,I=i.renderOnlyVisibleItems,O=void 0!==I&&I,R=i.style,k=s(null),x=n(0),C=e(x,2),D=C[0],L=C[1],V=c({refs:[u,k]}),_=v,N=s([]),W=l((function(e){var r=e.keyCode===m.UP_ARROW,t=e.keyCode===m.DOWN_ARROW,i=void 0;(r||t)&&(t&&N.current.length>D+1?i=D+1:r&&D>0&&(i=D-1),e.preventDefault(),void 0!==i&&(L(i),N.current[i].focus()))}),[D]),z=o((function(){var e=Array.isArray(b)?b:[b];return O?e=r(d,{children:e}):(N.current=N.current.slice(0,e.length),e=t.Children.map(e,(function(e,r){return t.isValidElement(e)?"string"==typeof e?e:t.cloneElement(e,{ref:function(e){return N.current[r]=e},tabIndex:D===r?0:-1}):e}))),e}),[b,D,O]);return r(_,Object.assign({ref:V,style:R,onKeyDown:O?void 0:W,className:a("l3-style-list",f,{"l3-style-list--dense":j,"l3-style-list-container":O}),id:y,"aria-label":g,"aria-describedby":A,tabIndex:-1},{children:z}))}));export{u as default};
