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