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