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