import e from"../_util/classNames.mjs";import t from"../_util/props-util/initDefaultProps.mjs";import{isValidElement as n}from"../_util/props-util/index.mjs";import r from"../_util/vue-types/index.mjs";import i from"../_util/KeyCode.mjs";import a from"../_util/createRef.mjs";import{toReactive as o}from"../_util/toReactive.mjs";import{cloneElement as ee}from"../_util/vnode.mjs";import te from"../vc-tree-select/LegacyContext.mjs";import s from"../vc-util/isMobile.mjs";import ne from"./SelectTrigger.mjs";import re from"./hooks/useLock.mjs";import c from"./TransBtn.mjs";import ie from"./Selector/index.mjs";import{useProvideBaseSelectProps as ae}from"./hooks/useBaseProps.mjs";import oe from"./hooks/useDelayReset.mjs";import l from"./hooks/useSelectTriggerControl.mjs";import{getSeparatedContent as u}from"./utils/valueUtil.mjs";import{computed as d,createTextVNode as se,createVNode as f,defineComponent as p,onBeforeUnmount as m,onMounted as h,provide as g,ref as _,shallowRef as v,toRefs as y,watch as b,watchEffect as ce}from"vue";var le=[`value`,`onChange`,`removeIcon`,`placeholder`,`autofocus`,`maxTagCount`,`maxTagTextLength`,`maxTagPlaceholder`,`choiceTransitionName`,`onInputKeyDown`,`onPopupScroll`,`tabindex`,`OptionList`,`notFoundContent`],x=()=>({prefixCls:String,id:String,omitDomProps:Array,displayValues:Array,onDisplayValuesChange:Function,activeValue:String,activeDescendantId:String,onActiveValueChange:Function,searchValue:String,onSearch:Function,onSearchSplit:Function,maxLength:Number,OptionList:r.any,emptyOptions:Boolean}),S=()=>({showSearch:{type:Boolean,default:void 0},tagRender:{type:Function},optionLabelRender:{type:Function},direction:{type:String},tabindex:Number,autofocus:Boolean,notFoundContent:r.any,placeholder:r.any,onClear:Function,choiceTransitionName:String,mode:String,disabled:{type:Boolean,default:void 0},loading:{type:Boolean,default:void 0},open:{type:Boolean,default:void 0},defaultOpen:{type:Boolean,default:void 0},onDropdownVisibleChange:{type:Function},getInputElement:{type:Function},getRawInputElement:{type:Function},maxTagTextLength:Number,maxTagCount:{type:[String,Number]},maxTagPlaceholder:r.any,tokenSeparators:{type:Array},allowClear:{type:Boolean,default:void 0},showArrow:{type:Boolean,default:void 0},inputIcon:r.any,clearIcon:r.any,removeIcon:r.any,animation:String,transitionName:String,dropdownStyle:{type:Object},dropdownClassName:String,dropdownMatchSelectWidth:{type:[Boolean,Number],default:void 0},dropdownRender:{type:Function},dropdownAlign:Object,placement:{type:String},getPopupContainer:{type:Function},showAction:{type:Array},onBlur:{type:Function},onFocus:{type:Function},onKeyup:Function,onKeydown:Function,onMousedown:Function,onPopupScroll:Function,onInputKeyDown:Function,onMouseenter:Function,onMouseleave:Function,onClick:Function}),C=()=>({...x(),...S()});function w(e){return e===`tags`||e===`multiple`}var T=p({compatConfig:{MODE:3},name:`BaseSelect`,inheritAttrs:!1,props:t(C(),{showAction:[],notFoundContent:`Not Found`}),setup(t,{attrs:r,expose:p,slots:x}){let S=d(()=>w(t.mode)),C=d(()=>t.showSearch===void 0?S.value||t.mode===`combobox`:t.showSearch),T=v(!1);h(()=>{T.value=s()});let ue=te(),E=v(null),D=a(),O=v(null),k=v(null),A=v(null),j=_(!1),[M,N,de]=oe();p({focus:()=>{k.value?.focus()},blur:()=>{k.value?.blur()},scrollTo:e=>A.value?.scrollTo(e)});let P=d(()=>{if(t.mode!==`combobox`)return t.searchValue;let e=t.displayValues[0]?.value;return typeof e==`string`||typeof e==`number`?String(e):``}),F=t.open===void 0?t.defaultOpen:t.open,I=v(F),L=v(F),R=e=>{I.value=t.open===void 0?e:t.open,L.value=I.value};b(()=>t.open,()=>{R(t.open)});let z=d(()=>!t.notFoundContent&&t.emptyOptions);ce(()=>{L.value=I.value,(t.disabled||z.value&&L.value&&t.mode===`combobox`)&&(L.value=!1)});let B=d(()=>!z.value&&L.value),V=e=>{let n=e===void 0?!L.value:e;L.value!==n&&!t.disabled&&(R(n),t.onDropdownVisibleChange&&t.onDropdownVisibleChange(n),!n&&K.value&&(K.value=!1,N(!1,()=>{G.value=!1,j.value=!1})))},fe=d(()=>(t.tokenSeparators||[]).some(e=>[`
`,`\r
`].includes(e))),H=(e,n,r)=>{let i=!0,a=e;t.onActiveValueChange?.(null);let o=r?null:u(e,t.tokenSeparators);return t.mode!==`combobox`&&o&&(a=``,t.onSearchSplit?.(o),V(!1),i=!1),t.onSearch&&P.value!==a&&t.onSearch(a,{source:n?`typing`:`effect`}),i},pe=e=>{!e||!e.trim()||t.onSearch?.(e,{source:`submit`})};b(L,()=>{!L.value&&!S.value&&t.mode!==`combobox`&&H(``,!1,!1)},{immediate:!0,flush:`post`}),b(()=>t.disabled,()=>{I.value&&t.disabled&&R(!1),t.disabled&&!j.value&&N(!1)},{immediate:!0});let[me,he]=re(),U=(e,...n)=>{let r=me(),{which:a}=e;if(a===i.ENTER&&(t.mode!==`combobox`&&e.preventDefault(),L.value||V(!0)),he(!!P.value),a===i.BACKSPACE&&!r&&S.value&&!P.value&&t.displayValues.length){let e=[...t.displayValues],n=null;for(let t=e.length-1;t>=0;--t){let r=e[t];if(!r.disabled){e.splice(t,1),n=r;break}}n&&t.onDisplayValuesChange(e,{type:`remove`,values:[n]})}L.value&&A.value&&A.value.onKeydown(e,...n),t.onKeydown?.(e,...n)},W=(e,...n)=>{L.value&&A.value&&A.value.onKeyup(e,...n),t.onKeyup&&t.onKeyup(e,...n)},ge=e=>{let n=t.displayValues.filter(t=>t!==e);t.onDisplayValuesChange(n,{type:`remove`,values:[e]})},G=v(!1),_e=(...e)=>{N(!0),t.disabled||(t.onFocus&&!G.value&&t.onFocus(...e),t.showAction&&t.showAction.includes(`focus`)&&V(!0)),G.value=!0},K=_(!1),ve=(...e)=>{if(K.value||(j.value=!0,N(!1,()=>{G.value=!1,j.value=!1,V(!1)}),t.disabled))return;let n=P.value;n&&(t.mode===`tags`?t.onSearch(n,{source:`submit`}):t.mode===`multiple`&&t.onSearch(``,{source:`blur`})),t.onBlur&&t.onBlur(...e)},ye=()=>{K.value=!0},be=()=>{K.value=!1};g(`VCSelectContainerEvent`,{focus:_e,blur:ve});let q=[];h(()=>{q.forEach(e=>clearTimeout(e)),q.splice(0,q.length)}),m(()=>{q.forEach(e=>clearTimeout(e)),q.splice(0,q.length)});let xe=(e,...n)=>{let{target:r}=e,i=O.value?.getPopupElement();if(i&&i.contains(r)){let e=setTimeout(()=>{let t=q.indexOf(e);t!==-1&&q.splice(t,1),de(),!T.value&&!i.contains(document.activeElement)&&k.value?.focus()});q.push(e)}t.onMousedown?.(e,...n)},J=v(null),Se=()=>{};return h(()=>{b(B,()=>{if(B.value){let e=Math.ceil(E.value?.offsetWidth);J.value!==e&&!Number.isNaN(e)&&(J.value=e)}},{immediate:!0,flush:`post`})}),l([E,O],B,V),ae(o({...y(t),open:L,triggerOpen:B,showSearch:C,multiple:S,toggleOpen:V})),()=>{let{prefixCls:i,id:a,open:o,defaultOpen:te,mode:s,showSearch:re,searchValue:ae,onSearch:oe,allowClear:l,clearIcon:u,showArrow:d,inputIcon:p,disabled:m,loading:h,getInputElement:g,getPopupContainer:_,placement:v,animation:y,transitionName:b,dropdownStyle:ce,dropdownClassName:w,dropdownMatchSelectWidth:T,dropdownRender:j,dropdownAlign:N,showAction:de,direction:F,tokenSeparators:I,tagRender:R,optionLabelRender:z,onPopupScroll:me,onDropdownVisibleChange:he,onFocus:G,onBlur:_e,onKeyup:K,onKeydown:ve,onMousedown:q,onClear:Ce,omitDomProps:we,getRawInputElement:Y,displayValues:X,onDisplayValuesChange:Te,emptyOptions:Ee,activeDescendantId:De,activeValue:Oe,OptionList:ke,...Ae}={...t,...r},Z=s===`combobox`&&g&&g()||null,Q=typeof Y==`function`&&Y(),$={...Ae},je;Q&&(je=e=>{V(e)}),le.forEach(e=>{delete $[e]}),we?.forEach(e=>{delete $[e]});let Me=d===void 0?h||!S.value&&s!==`combobox`:d,Ne;Me&&(Ne=f(c,{class:e(`${i}-arrow`,{[`${i}-arrow-loading`]:h}),customizeIcon:p,customizeIconProps:{loading:h,searchValue:P.value,open:L.value,focused:M.value,showSearch:C.value}},null));let Pe;!m&&l&&(X.length||P.value)&&(Pe=f(c,{class:`${i}-clear`,onMousedown:()=>{Ce?.(),Te([],{type:`clear`,values:X}),H(``,!1,!1)},customizeIcon:u},{default:()=>[se(`×`)]}));let Fe=f(ke,{ref:A},{...ue.customSlots,option:x.option}),Ie=e(i,r.class,{[`${i}-focused`]:M.value,[`${i}-multiple`]:S.value,[`${i}-single`]:!S.value,[`${i}-allow-clear`]:l,[`${i}-show-arrow`]:Me,[`${i}-disabled`]:m,[`${i}-loading`]:h,[`${i}-open`]:L.value,[`${i}-customize-input`]:Z,[`${i}-show-search`]:C.value}),Le=f(ne,{ref:O,disabled:m,prefixCls:i,visible:B.value,popupElement:Fe,containerWidth:J.value,animation:y,transitionName:b,dropdownStyle:ce,dropdownClassName:w,direction:F,dropdownMatchSelectWidth:T,dropdownRender:j,dropdownAlign:N,placement:v,getPopupContainer:_,empty:Ee,getTriggerDOMNode:()=>D.current,onPopupVisibleChange:je,onPopupMouseEnter:Se,onPopupFocusin:ye,onPopupFocusout:be},{default:()=>Q?n(Q)&&ee(Q,{ref:D,tabindex:0},!1,!0):f(ie,{...t,domRef:D,prefixCls:i,inputElement:Z,ref:k,id:a,showSearch:C.value,mode:s,activeDescendantId:De,tagRender:R,optionLabelRender:z,values:X,open:L.value,onToggleOpen:V,activeValue:Oe,searchValue:P.value,onSearch:H,onSearchSubmit:pe,onRemove:ge,tokenWithEnter:fe.value},null)}),Re;return Re=Q?f(`div`,{onKeydown:U,onKeyup:W},[Le]):f(`div`,{...$,class:Ie,ref:E,onMousedown:xe,onKeydown:U,onKeyup:W},[M.value&&!L.value&&f(`span`,{style:{width:0,height:0,position:`absolute`,overflow:`hidden`,opacity:0},"aria-live":`polite`},[`${X.map(({label:e,value:t})=>[`number`,`string`].includes(typeof e)?e:t).join(`, `)}`]),Le,Ne,Pe]),Re}}});export{S as baseSelectPropsWithoutPrivate,T as default,w as isMultiple};