import{defineComponent as H,ref as J,computed as i,shallowRef as Q,watchEffect as U,onMounted as W,watch as Z,createVNode as w}from"vue";import"../../vc-select/BaseSelect.mjs";import"../../vc-select/OptGroup.mjs";import"../../vc-select/Option.mjs";import"../../vc-select/Select.mjs";import ee from"../../vc-select/hooks/useBaseProps.mjs";import{useInjectCascader as te}from"../context.mjs";import{toPathValueStr as oe,isLeaf as v,toPathKeys as b,toPathKey as K,scrollIntoParentView as ne}from"../utils/commonUtil.mjs";import{toPathOptions as k}from"../utils/treeUtil.mjs";import le,{FIX_LABEL as ae}from"./Column.mjs";import se from"./useActive.mjs";import ue from"./useKeyboard.mjs";const ye=H({compatConfig:{MODE:3},name:"OptionList",inheritAttrs:!1,setup(re,d){const{attrs:E,slots:M}=d,s=ee(),g=J(),_=i(()=>s.direction==="rtl"),{options:m,values:A,halfValues:D,fieldNames:a,changeOnSelect:O,onSelect:F,searchOptions:$,dropdownPrefixCls:I,loadData:C,expandTrigger:N,customSlots:T}=te(),p=i(()=>I.value||s.prefixCls),u=Q([]),x=e=>{if(!C.value||s.searchValue)return;const o=k(e,m.value,a.value).map(({option:l})=>l),n=o[o.length-1];if(n&&!v(n,a.value)){const l=K(e);u.value=[...u.value,l],C.value(o)}};U(()=>{u.value.length&&u.value.forEach(e=>{const t=oe(e),o=k(t,m.value,a.value,!0).map(({option:l})=>l),n=o[o.length-1];(!n||n[a.value.children]||v(n,a.value))&&(u.value=u.value.filter(l=>l!==e))})});const B=i(()=>new Set(b(A.value))),R=i(()=>new Set(b(D.value))),[r,j]=se(),P=e=>{j(e),x(e)},S=e=>{const{disabled:t}=e,o=v(e,a.value);return!t&&(o||O.value||s.multiple)},y=(e,t,o=!1)=>{F(e),!s.multiple&&(t||O.value&&(N.value==="hover"||o))&&s.toggleOpen(!1)},f=i(()=>s.searchValue?$.value:m.value),L=i(()=>{const e=[{options:f.value}];let t=f.value;for(let o=0;o<r.value.length;o+=1){const n=r.value[o],c=t.find(V=>V[a.value.value]===n)?.[a.value.children];if(!c?.length)break;t=c,e.push({options:c})}return e});ue(d,f,a,r,P,(e,t)=>{S(t)&&y(e,v(t,a.value),!0)});const q=e=>{e.preventDefault()};return W(()=>{Z(r,e=>{for(let t=0;t<e.length;t+=1){const o=e.slice(0,t+1),n=K(o),l=g.value?.querySelector(`li[data-path-key="${n.replace(/\\{0,2}"/g,'\\"')}"]`);l&&ne(l)}},{flush:"post",immediate:!0})}),()=>{const{notFoundContent:e=M.notFoundContent?.()||T.value.notFoundContent?.(),multiple:t,toggleOpen:o}=s,n=!L.value[0]?.options?.length,l=[{[a.value.value]:"__EMPTY__",[ae]:e,disabled:!0}],c={...E,multiple:!n&&t,onSelect:y,onActive:P,onToggleOpen:o,checkedSet:B.value,halfCheckedSet:R.value,loadingKeys:u.value,isSelectable:S},X=(n?[{options:l}]:L.value).map((Y,h)=>{const z=r.value.slice(0,h),G=r.value[h];return w(le,{key:h,...c,prefixCls:p.value,options:Y.options,prevValuePath:z,activeValue:G},null)});return w("div",{class:[`${p.value}-menus`,{[`${p.value}-menu-empty`]:n,[`${p.value}-rtl`]:_.value}],onMousedown:q,ref:g},[X])}}});export{ye as default};
