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