import{defineComponent as K,shallowRef as g,computed as h,ref as A,watchEffect as z,onMounted as W,watch as j,createVNode as i,createTextVNode as S,Fragment as q}from"vue";import G from"../../_util/classNames.mjs";import H from"../../_util/pickAttrs.mjs";import a from"../../_util/vue-types/index.mjs";import J from"../../vc-overflow/Overflow.mjs";import Q from"../../vc-tree-select/LegacyContext.mjs";import U from"../TransBtn.mjs";import X from"./Input.mjs";const Y={id:String,prefixCls:String,values:a.array,open:{type:Boolean,default:void 0},searchValue:String,inputRef:a.any,placeholder:a.any,disabled:{type:Boolean,default:void 0},mode:String,showSearch:{type:Boolean,default:void 0},autofocus:{type:Boolean,default:void 0},autocomplete:String,activeDescendantId:String,tabindex:a.oneOfType([a.number,a.string]),compositionStatus:Boolean,removeIcon:a.any,choiceTransitionName:String,maxTagCount:a.oneOfType([a.number,a.string]),maxTagTextLength:Number,maxTagPlaceholder:a.any.def(()=>e=>`+ ${e.length} ...`),tagRender:Function,onToggleOpen:{type:Function},onRemove:Function,onInputChange:Function,onInputPaste:Function,onInputKeyDown:Function,onInputMouseDown:Function,onInputCompositionStart:Function,onInputCompositionEnd:Function},I=e=>{e.preventDefault(),e.stopPropagation()},le=K({name:"MultipleSelectSelector",inheritAttrs:!1,props:Y,setup(e){const v=g(),y=g(0),p=g(!1),x=Q(),s=h(()=>`${e.prefixCls}-selection`),b=h(()=>e.open||e.mode==="tags"?e.searchValue:""),T=h(()=>e.mode==="tags"||e.showSearch&&(e.open||p.value)),m=A("");z(()=>{m.value=b.value}),W(()=>{j(m,()=>{y.value=v.value.scrollWidth},{flush:"post",immediate:!0})});function C(n,t,o,l,r){return i("span",{class:G(`${s.value}-item`,{[`${s.value}-item-disabled`]:o}),title:typeof n=="string"||typeof n=="number"?n.toString():void 0},[i("span",{class:`${s.value}-item-content`},[t]),l&&i(U,{class:`${s.value}-item-remove`,onMousedown:I,onClick:r,customizeIcon:e.removeIcon},{default:()=>[S("×")]})])}function w(n,t,o,l,r,f){const c=u=>{I(u),e.onToggleOpen(!e.open)};let d=f;return x.keyEntities&&(d=x.keyEntities[n]?.node||{}),i("span",{key:n,onMousedown:c},[e.tagRender({label:t,value:n,disabled:o,closable:l,onClose:r,option:d})])}function R(n){const{disabled:t,label:o,value:l,option:r}=n,f=!e.disabled&&!t;let c=o;if(typeof e.maxTagTextLength=="number"&&(typeof o=="string"||typeof o=="number")){const u=String(c);u.length>e.maxTagTextLength&&(c=`${u.slice(0,e.maxTagTextLength)}...`)}const d=u=>{u&&u.stopPropagation(),e.onRemove?.(n)};return typeof e.tagRender=="function"?w(l,c,t,f,d,r):C(o,c,t,f,d)}function D(n){const{maxTagPlaceholder:t=l=>`+ ${l.length} ...`}=e,o=typeof t=="function"?t(n):t;return C(o,o,!1)}const $=n=>{const t=n.target.composing;m.value=n.target.value,t||e.onInputChange(n)};return()=>{const{id:n,prefixCls:t,values:o,open:l,inputRef:r,placeholder:f,disabled:c,autofocus:d,autocomplete:u,activeDescendantId:F,tabindex:P,compositionStatus:M,onInputPaste:k,onInputKeyDown:B,onInputMouseDown:E,onInputCompositionStart:L,onInputCompositionEnd:N}=e,V=i("div",{class:`${s.value}-search`,style:{width:`${y.value}px`},key:"input"},[i(X,{inputRef:r,open:l,prefixCls:t,id:n,inputElement:null,disabled:c,autofocus:d,autocomplete:u,editable:T.value,activeDescendantId:F,value:m.value,onKeydown:B,onMousedown:E,onChange:$,onPaste:k,onCompositionstart:L,onCompositionend:N,tabindex:P,attrs:H(e,!0),onFocus:()=>p.value=!0,onBlur:()=>p.value=!1},null),i("span",{ref:v,class:`${s.value}-search-mirror`,"aria-hidden":!0},[m.value,S(" ")])]),O=i(J,{prefixCls:`${s.value}-overflow`,data:o,renderItem:R,renderRest:D,suffix:V,itemKey:"key",maxCount:e.maxTagCount,key:"overflow"},null);return i(q,null,[O,!o.length&&!b.value&&!M&&i("span",{class:`${s.value}-placeholder`},[f])])}}});export{le as default};
