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