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