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