import e from"../../_util/KeyCode.mjs";import t from"../../vc-select/hooks/useBaseProps.mjs";import"../hooks/useSearchOptions.mjs";import{computed as n,ref as r,watchEffect as i}from"vue";var a=(a,o,s,c,l,u)=>{let d=t(),f=n(()=>d.direction===`rtl`),[p,m,h]=[r([]),r(),r([])];i(()=>{let e=-1,t=o.value,n=[],r=[],i=c.value.length;for(let a=0;a<i&&t;a+=1){let i=t.findIndex(e=>e[s.value.value]===c.value[a]);if(i===-1)break;e=i,n.push(e),r.push(c.value[a]),t=t[e][s.value.children]}let a=o.value;for(let e=0;e<n.length-1;e+=1)a=a[n[e]][s.value.children];[p.value,m.value,h.value]=[r,e,a]});let g=e=>{l(e)},_=e=>{let t=h.value.length,n=m.value;n===-1&&e<0&&(n=t);for(let r=0;r<t;r+=1){n=(n+e+t)%t;let r=h.value[n];if(r&&!r.disabled){let e=r[s.value.value],t=p.value.slice(0,-1).concat(e);g(t);return}}},v=()=>{if(p.value.length>1){let e=p.value.slice(0,-1);g(e)}else d.toggleOpen(!1)},y=()=>{let e=(h.value[m.value]?.[s.value.children]||[]).find(e=>!e.disabled);if(e){let t=[...p.value,e[s.value.value]];g(t)}};a.expose({onKeydown:t=>{let{which:n}=t;switch(n){case e.UP:case e.DOWN:{let t=0;n===e.UP?t=-1:n===e.DOWN&&(t=1),t!==0&&_(t);break}case e.LEFT:f.value?y():v();break;case e.RIGHT:f.value?v():y();break;case e.BACKSPACE:d.searchValue||v();break;case e.ENTER:if(p.value.length){let e=h.value[m.value],t=e?.__rc_cascader_search_mark__||[];t.length?u(t.map(e=>e[s.value.value]),t[t.length-1]):u(p.value,e)}break;case e.ESC:d.toggleOpen(!1),open&&t.stopPropagation()}},onKeyup:()=>{}})};export{a as default};