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