import{computed as P,ref as x,watchEffect as K}from"vue";import a from"../../_util/KeyCode.mjs";import"../../vc-select/BaseSelect.mjs";import"../../vc-select/OptGroup.mjs";import"../../vc-select/Option.mjs";import"../../vc-select/Select.mjs";import w from"../../vc-select/hooks/useBaseProps.mjs";import{SEARCH_MARK as R}from"../hooks/useSearchOptions.mjs";const B=(b,g,s,f,E,A)=>{const r=w(),m=P(()=>r.direction==="rtl"),[i,p,u]=[x([]),x(),x([])];K(()=>{let l=-1,t=g.value;const e=[],n=[],c=f.value.length;for(let o=0;o<c&&t;o+=1){const C=t.findIndex(k=>k[s.value.value]===f.value[o]);if(C===-1)break;l=C,e.push(l),n.push(f.value[o]),t=t[l][s.value.children]}let v=g.value;for(let o=0;o<e.length-1;o+=1)v=v[e[o]][s.value.children];[i.value,p.value,u.value]=[n,l,v]});const d=l=>{E(l)},I=l=>{const t=u.value.length;let e=p.value;e===-1&&l<0&&(e=t);for(let n=0;n<t;n+=1){e=(e+l+t)%t;const c=u.value[e];if(c&&!c.disabled){const v=c[s.value.value],o=i.value.slice(0,-1).concat(v);d(o);return}}},h=()=>{if(i.value.length>1){const l=i.value.slice(0,-1);d(l)}else r.toggleOpen(!1)},O=()=>{const t=(u.value[p.value]?.[s.value.children]||[]).find(e=>!e.disabled);if(t){const e=[...i.value,t[s.value.value]];d(e)}};b.expose({onKeydown:l=>{const{which:t}=l;switch(t){case a.UP:case a.DOWN:{let e=0;t===a.UP?e=-1:t===a.DOWN&&(e=1),e!==0&&I(e);break}case a.LEFT:{m.value?O():h();break}case a.RIGHT:{m.value?h():O();break}case a.BACKSPACE:{r.searchValue||h();break}case a.ENTER:{if(i.value.length){const e=u.value[p.value],n=e?.[R]||[];n.length?A(n.map(c=>c[s.value.value]),n[n.length-1]):A(i.value,e)}break}case a.ESC:r.toggleOpen(!1),open&&l.stopPropagation()}},onKeyup:()=>{}})};export{B as default};
