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