import{defineComponent as M,shallowRef as $,computed as u,watch as A,createVNode as i,Fragment as v}from"vue";import N from"../../_util/pickAttrs.mjs";import o from"../../_util/vue-types/index.mjs";import j from"../../vc-tree-select/LegacyContext.mjs";import O from"./Input.mjs";const q={inputElement:o.any,id:String,prefixCls:String,values:o.array,open:{type:Boolean,default:void 0},searchValue:String,inputRef:o.any,placeholder:o.any,compositionStatus:{type:Boolean,default:void 0},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:o.oneOfType([o.number,o.string]),activeValue:String,backfill:{type:Boolean,default:void 0},optionLabelRender:Function,onInputChange:Function,onInputPaste:Function,onInputKeyDown:Function,onInputMouseDown:Function,onInputCompositionStart:Function,onInputCompositionEnd:Function},y=M({name:"SingleSelector",setup(e){const d=$(!1),l=u(()=>e.mode==="combobox"),b=u(()=>l.value||e.showSearch),r=u(()=>{let t=e.searchValue||"";return l.value&&e.activeValue&&!d.value&&(t=e.activeValue),t}),s=j();A([l,()=>e.activeValue],()=>{l.value&&(d.value=!1)},{immediate:!0});const p=u(()=>e.mode!=="combobox"&&!e.open&&!e.showSearch?!1:!!r.value||e.compositionStatus),S=u(()=>{const t=e.values[0];return t&&(typeof t.label=="string"||typeof t.label=="number")?t.label.toString():void 0}),g=()=>{if(e.values[0])return null;const t=p.value?{visibility:"hidden"}:void 0;return i("span",{class:`${e.prefixCls}-selection-placeholder`,style:t},[e.placeholder])},h=t=>{t.target.composing||(d.value=!0,e.onInputChange(t))};return()=>{const{inputElement:t,prefixCls:c,id:I,values:C,inputRef:x,disabled:w,autofocus:V,autocomplete:D,activeDescendantId:F,open:k,tabindex:E,optionLabelRender:f,onInputKeyDown:B,onInputMouseDown:R,onInputPaste:P,onInputCompositionStart:T,onInputCompositionEnd:K}=e,n=C[0];let a=null;if(n&&s.customSlots){const L=n.key??n.value,m=s.keyEntities[L]?.node||{};a=s.customSlots[m.slots?.title]||s.customSlots.title||n.label,typeof a=="function"&&(a=a(m))}else a=f&&n?f(n.option):n?.label;return i(v,null,[i("span",{class:`${c}-selection-search`},[i(O,{inputRef:x,prefixCls:c,id:I,open:k,inputElement:t,disabled:w,autofocus:V,autocomplete:D,editable:b.value,activeDescendantId:F,value:r.value,onKeydown:B,onMousedown:R,onChange:h,onPaste:P,onCompositionstart:T,onCompositionend:K,tabindex:E,attrs:N(e,!0)},null)]),!l.value&&n&&!p.value&&i("span",{class:`${c}-selection-item`,title:S.value},[i(v,{key:n.key??n.value},[a])]),g()])}}});y.props=q;y.inheritAttrs=!1;export{y as default};
