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