import{slicedToArray as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import{useState as t,useMemo as s,useCallback as o}from"react";import{useSetDefaultItemOnFocusEvent as i,useSupportArrowsKeyboardNavigation as n,useSupportPressItemKeyboardNavigation as u,useKeepFocusOnItemWhenListChanged as l,useCleanVisualFocusOnBlur as c}from"./useActiveDescendantListFocusHooks.js";var r;function a(a){var m=a.focusedElementRef,I=a.itemsIds,d=a.isItemSelectable,f=a.onItemClick,v=a.defaultVisualFocusFirstIndex,p=a.focusedElementRole,x=void 0===p?r.GROUP:p,F=a.isHorizontalList,b=void 0!==F&&F,O=a.useDocumentEventListeners,C=void 0!==O&&O,E=a.isIgnoreSpaceAsItemSelection,g=void 0!==E&&E,S=void 0!==v&&v?0:-1,P=I.length,R=t(-1),V=e(R,2),k=V[0],A=V[1],B=I[k],y=s((function(){if(!C)return{ref:m,preventDefault:!0,stopPropagation:!0}}),[C,m]),L=i({focusedElementRef:m,isItemSelectable:d,visualFocusItemIndex:k,setVisualFocusItemIndex:A,itemsCount:P,defaultVisualFocusItemIndex:S}).triggeredByKeyboard,T=o((function(e,t){L.current=t;var s=I.indexOf(e);s>-1&&s!==k&&A(s)}),[I,L,k]);n({itemsCount:P,focusedElementRef:m,visualFocusItemIndex:k,setVisualFocusItemIndex:A,triggeredByKeyboard:L,isHorizontalList:b,isItemSelectable:d,listenerOptions:y}),u({visualFocusItemIndex:k,itemsCount:P,focusedElementRef:m,setVisualFocusItemIndex:A,onItemClick:f,isItemSelectable:d,listenerOptions:y,isIgnoreSpaceAsItemSelection:g}),l({visualFocusItemIndex:k,itemsIds:I,isItemSelectable:d,setVisualFocusItemIndex:A}),c({focusedElementRef:m,visualFocusItemIndex:k,setVisualFocusItemIndex:A});var H=o((function(e){return function(t){return f(t,e)}}),[f]);return{visualFocusItemIndex:L.current?k:void 0,visualFocusItemId:L.current?B:void 0,focusedElementProps:{"aria-activedescendant":L.current?B:void 0,role:x},onItemClickCallback:f,createOnItemClickCallback:H,setVisualFocusItemId:T}}!function(e){e.APPLICATION="application",e.COMBOBOX="combobox",e.COMPOSITE="composite",e.GROUP="group",e.TEXTBOX="textbox",e.MENU="menu"}(r||(r={})),a.roles=r;export{a as default};
