import e from"../../_util/vue-types/index.mjs";import t from"../../_util/KeyCode.mjs";import n from"../../_util/createRef.mjs";import r from"../hooks/useLock.mjs";import{isValidateOpenKey as i}from"../utils/keyUtil.mjs";import a from"./MultipleSelector.mjs";import o from"./SingleSelector.mjs";import{createVNode as s,defineComponent as c,ref as l}from"vue";var u=c({name:`Selector`,inheritAttrs:!1,props:{id:String,prefixCls:String,showSearch:{type:Boolean,default:void 0},open:{type:Boolean,default:void 0},values:e.array,multiple:{type:Boolean,default:void 0},mode:String,searchValue:String,activeValue:String,inputElement:e.any,autofocus:{type:Boolean,default:void 0},activeDescendantId:String,tabindex:e.oneOfType([e.number,e.string]),disabled:{type:Boolean,default:void 0},placeholder:e.any,removeIcon:e.any,maxTagCount:e.oneOfType([e.number,e.string]),maxTagTextLength:Number,maxTagPlaceholder:e.any,tagRender:Function,optionLabelRender:Function,tokenWithEnter:{type:Boolean,default:void 0},choiceTransitionName:String,onToggleOpen:{type:Function},onSearch:Function,onSearchSubmit:Function,onRemove:Function,onInputKeyDown:{type:Function},domRef:Function},setup(e,{expose:c}){let u=n(),d=l(!1),[f,p]=r(0),m=n=>{let{which:r}=n;(r===t.UP||r===t.DOWN)&&n.preventDefault(),e.onInputKeyDown&&e.onInputKeyDown(n),r===t.ENTER&&e.mode===`tags`&&!d.value&&!e.open&&e.onSearchSubmit(n.target.value),i(r)&&e.onToggleOpen(!0)},h=()=>{p(!0)},g=null,_=t=>{e.onSearch(t,!0,d.value)!==!1&&e.onToggleOpen(!0)},v=()=>{d.value=!0},y=t=>{d.value=!1,e.mode!==`combobox`&&_(t.target.value)},b=t=>{let{target:{value:n}}=t;if(e.tokenWithEnter&&g&&/[\r\n]/.test(g)){let e=g.replace(/[\r\n]+$/,``).replace(/\r\n/g,` `).replace(/[\r\n]/g,` `);n=n.replace(e,g)}g=null,_(n)},x=e=>{let{clipboardData:t}=e;g=t.getData(`text`)},S=({target:e})=>{e!==u.current&&(document.body.style.msTouchAction===void 0?u.current.focus():setTimeout(()=>{u.current.focus()}))},C=t=>{let n=f();t.target!==u.current&&!n&&t.preventDefault(),(e.mode!==`combobox`&&(!e.showSearch||!n)||!e.open)&&(e.open&&e.onSearch(``,!0,!1),e.onToggleOpen())};return c({focus:()=>{u.current.focus()},blur:()=>{u.current.blur()}}),()=>{let{prefixCls:t,domRef:n,mode:r}=e,i={inputRef:u,onInputKeyDown:m,onInputMouseDown:h,onInputChange:b,onInputPaste:x,compositionStatus:d.value,onInputCompositionStart:v,onInputCompositionEnd:y},c=s(r===`multiple`||r===`tags`?a:o,{...e,...i},null);return s(`div`,{ref:n,class:`${t}-selector`,onClick:S,onMousedown:C},[c])}}});export{u as default};