import e from"../_util/KeyCode.mjs";import t from"./LegacyContext.mjs";import n from"../vc-select/hooks/useBaseProps.mjs";import r from"../_util/hooks/useMemo.mjs";import i from"../vc-tree/Tree.mjs";import a from"./TreeSelectContext.mjs";import{getAllKeys as o,isCheckDisabled as s}from"./utils/valueUtil.mjs";import{computed as c,createVNode as l,defineComponent as u,nextTick as d,ref as f,shallowRef as p,toRaw as m,watch as h}from"vue";var g={width:0,height:0,display:`flex`,overflow:`hidden`,opacity:0,border:0,padding:0,margin:0},_=u({compatConfig:{MODE:3},name:`OptionList`,inheritAttrs:!1,setup(u,{slots:_,expose:v}){let y=n(),b=t(),x=a(),S=f(),C=r(()=>x.treeData,[()=>y.open,()=>x.treeData],e=>e[0]),w=c(()=>{let{checkable:e,halfCheckedKeys:t,checkedKeys:n}=b;return e?{checked:n,halfChecked:t}:null});h(()=>y.open,()=>{d(()=>{y.open&&!y.multiple&&b.checkedKeys.length&&S.value?.scrollTo({key:b.checkedKeys[0]})})},{immediate:!0,flush:`post`});let T=c(()=>String(y.searchValue).toLowerCase()),E=e=>T.value?String(e[b.treeNodeFilterProp]).toLowerCase().includes(T.value):!1,D=p(b.treeDefaultExpandedKeys),O=p(null);h(()=>y.searchValue,()=>{y.searchValue&&(O.value=o(m(x.treeData),m(x.fieldNames)))},{immediate:!0});let k=c(()=>b.treeExpandedKeys?b.treeExpandedKeys.slice():y.searchValue?O.value:D.value),A=e=>{D.value=e,O.value=e,b.onTreeExpand?.(e)},j=e=>{e.preventDefault()},M=(e,{node:t})=>{let{checkable:n,checkedKeys:r}=b;n&&s(t)||(x.onSelect?.(t.key,{selected:!r.includes(t.key)}),y.multiple||y.toggleOpen?.(!1))},N=f(null),P=c(()=>b.keyEntities[N.value]),F=e=>{N.value=e};return v({scrollTo:(...e)=>S.value?.scrollTo?.(...e),onKeydown:t=>{let{which:n}=t;switch(n){case e.UP:case e.DOWN:case e.LEFT:case e.RIGHT:S.value?.onKeydown(t);break;case e.ENTER:if(P.value){let{selectable:e,value:t}=P.value.node||{};e!==!1&&M(null,{node:{key:N.value},selected:!b.checkedKeys.includes(t)})}break;case e.ESC:y.toggleOpen(!1)}},onKeyup:()=>{}}),()=>{let{prefixCls:e,multiple:t,searchValue:n,open:r,notFoundContent:a=_.notFoundContent?.()}=y,{listHeight:o,listItemHeight:s,virtual:c,dropdownMatchSelectWidth:u,treeExpandAction:d}=x,{checkable:f,treeDefaultExpandAll:p,treeIcon:m,showTreeIcon:h,switcherIcon:v,treeLine:T,loadData:D,treeLoadedKeys:O,treeMotion:I,onTreeLoad:L,checkedKeys:R}=b;if(C.value.length===0)return l(`div`,{role:`listbox`,class:`${e}-empty`,onMousedown:j},[a]);let z={fieldNames:x.fieldNames};return O&&(z.loadedKeys=O),k.value&&(z.expandedKeys=k.value),l(`div`,{onMousedown:j},[P.value&&r&&l(`span`,{style:g,"aria-live":`assertive`},[P.value.node.value]),l(i,{ref:S,focusable:!1,prefixCls:`${e}-tree`,treeData:C.value,height:o,itemHeight:s,virtual:c!==!1&&u!==!1,multiple:t,icon:m,showIcon:h,switcherIcon:v,showLine:T,loadData:n?null:D,motion:I,activeKey:N.value,checkable:f,checkStrictly:!0,checkedKeys:w.value,selectedKeys:f?[]:R,defaultExpandAll:p,...z,onActiveChange:F,onSelect:M,onCheck:M,onExpand:A,onLoad:L,filterTreeNode:E,expandAction:d},{..._,checkable:b.customSlots.treeCheckable})])}}});export{_ as default};