define(['exports', 'preact/jsx-runtime', 'preact', 'preact/hooks', 'preact/compat', './classNames-08d99695', './useId-c9578d26', './useTranslationBundle-7c40cb58', './keys-4755c121', './HiddenAccessible-037ef42d', './ChevronDown-502b16f2', './CollapseIcon-a7f8693d', './LiveRegion-1917f798', './useUser-797287de', './collectionUtils-f4de3e13', './Button-cb88d20f', './GroupLoadingIndicator-9fd33355', './List-37e37948'], (function(e,t,n,a,s,o,i,r,d,l,c,u,p,x,g,y,m,f){"use strict";const k=e=>{"Enter"!==e.key&&" "!==e.key&&"ArrowLeft"!==e.key&&"ArrowRight"!==e.key||e.preventDefault()},h=(e,t,n,a,s)=>{const o=a(t);if(s&&o){const t=d.containsKey(n,o);(e&&t||!e&&!t)&&s({value:o})}},v=(e,t,n)=>{const a=t(e.target);n&&a&&(n({value:a}),"click"===e.type&&e.stopPropagation())};const b={all:!1,keys:new Set},C=s.memo((e=>{const n=o.classNames(["oj-listview-expander"]);return t.jsx("span",{class:n,role:"presentation",children:t.jsx(y.Button,{onAction:()=>{e.onToggle({value:e.itemKey})},variant:"ghost",startIcon:e.expanded?t.jsx(c.SvgChevronDown,{size:"6x"}):t.jsx(u.CollapseIcon,{size:"6x"})})})}),((e,t)=>e.itemKey===t.itemKey&&e.expanded===t.expanded&&e.onToggle===t.onToggle));e.ExpandableList=function({children:e,data:s,onSelectionChange:o,onToggle:c,onPersistCurrentItem:u,...y}){const[L,j]=a.useState(""),I=r.useTranslationBundle("@oracle/oraclejet-preact"),K=a.useRef(),T=a.useCallback((e=>{K.current=e.value,u?.(e)}),[u]),A=a.useCallback((e=>{if(c?.(e),s){const t=d.containsKey(s?.expanded,e.value);j(t?I.expandableList_groupCollapse():I.expandableList_groupExpand()),setTimeout((()=>{j("")}),1e3)}}),[c,s,I]),R=function(e,t,n){const{direction:s}=x.useUser(),o=a.useCallback((t=>{v(t,e,n)}),[e,n]),i=a.useCallback((a=>{if("Enter"===a.key||" "===a.key)v(a,e,n);else if("ArrowLeft"===a.key||"ArrowRight"===a.key){const o="rtl"===s,i="ArrowLeft"===a.key&&!o;h(i,a.target,t,e,n),a.preventDefault(),a.stopPropagation()}}),[e,n,t,s]);return n?{onClick:o,onKeyDown:k,onKeyUp:i}:{}}((e=>"treegrid"===e.getAttribute("role")?void 0===K.current?null:K.current:g.keyExtractor(e,m.GROUP_SELECTOR)),null==s?b:s.expanded,c&&A),w=i.useId(),D=a.useRef(w),E=a.useCallback((e=>{if(o&&s){const t=f.excludeGroup(s,e.value);d.isSameKey(t,e.value)?o(e):t.keys&&t.keys.size>0&&o({...e,value:t})}}),[o,s]);return t.jsxs(n.Fragment,{children:[t.jsx(f.List,{data:s,role:"treegrid",loadingIndicator:t.jsx(m.GroupLoadingIndicator,{}),onSelectionChange:E,customItemRenderer:n=>{const a=n.listItemContext.metadata.key,o=s&&c?{expanded:d.containsKey(s.expanded,a),onToggle:c}:void 0,i=((e,n)=>{const a=void 0!==n?()=>t.jsx(C,{itemKey:e.metadata.key,expanded:n.expanded,onToggle:n.onToggle}):void 0;return{...e,parentKey:e.metadata.parentKey,leaf:e.metadata.isLeaf??!0,depth:e.metadata.treeDepth??1,expander:a}})(n.listItemContext,o);return i.leaf?n.defaultListItem(i,{itemDepth:i.depth+1}):t.jsx(m.ListGroupHeader,{ariaDescribedBy:D.current,itemKey:i.metadata.key,itemIndex:i.index,itemDepth:i.depth,isFocused:n.isFocused,isFocusRingVisible:n.isFocusRingVisible,isActive:n.isActive,isGridlineVisible:!1,isExpandable:!0,expandedKeys:null==s?b:s.expanded,onToggle:c,children:e(i)},i.metadata.key)},onPersistCurrentItem:T,...y,...R,children:t=>e(t)}),c&&t.jsxs(n.Fragment,{children:[t.jsx(p.LiveRegion,{children:L}),t.jsx("span",{id:D.current,children:t.jsx(l.HiddenAccessible,{children:I.expandableList_expandCollapseInstructionText()})})]})]})}}));
//# sourceMappingURL=ExpandableList-daabc548.js.map
