import{defineComponent as N,ref as v,createVNode as p}from"vue";import f from"../_util/omit.mjs";import{isValidElement as w,flattenChildren as A}from"../_util/props-util/index.mjs";import B from"../_util/warning.mjs";import E from"../config-provider/hooks/useConfigInject.mjs";import C,{selectProps as j}from"../select/index.mjs";import r from"./OptGroup.mjs";import o from"./Option.mjs";function x(e){return e?.type?.isSelectOption||e?.type?.isSelectOptGroup}const M=()=>({...f(j(),["loading","mode","optionLabelProp","labelInValue"]),dataSource:Array,dropdownMenuStyle:{type:Object,default:void 0},dropdownMatchSelectWidth:{type:[Number,Boolean],default:!0},prefixCls:String,showSearch:{type:Boolean,default:void 0},transitionName:String,choiceTransitionName:{type:String,default:"zoom"},autofocus:{type:Boolean,default:void 0},backfill:{type:Boolean,default:void 0},filterOption:{type:[Boolean,Function],default:!1},defaultActiveFirstOption:{type:Boolean,default:!0},status:String}),z=o,R=r,d=N({compatConfig:{MODE:3},name:"AAutoComplete",inheritAttrs:!1,props:M(),slots:Object,setup(e,{slots:n,attrs:m,expose:y}){B(!e.dropdownClassName);const u=v(),S=()=>{const l=A(n.default?.());return l.length?l[0]:void 0};y({focus:()=>{u.value?.focus()},blur:()=>{u.value?.blur()}});const{prefixCls:a}=E("select",e);return()=>{const{size:l,dataSource:s,notFoundContent:g=n.notFoundContent?.()}=e;let c;const{class:O}=m,h={[O]:!!O,[`${a.value}-lg`]:l==="large",[`${a.value}-sm`]:l==="small",[`${a.value}-show-search`]:!0,[`${a.value}-auto-complete`]:!0};if(e.options===void 0){const i=n.dataSource?.()||n.options?.()||[];i.length&&x(i[0])?c=i:c=s?s.map(t=>{if(w(t))return t;switch(typeof t){case"string":return p(o,{key:t,value:t},{default:()=>[t]});case"object":return p(o,{key:t.value,value:t.value},{default:()=>[t.text]});default:throw new Error("AutoComplete[dataSource] only supports type `string[] | Object[]`.")}}):[]}const b=f({...e,...m,mode:C.SECRET_COMBOBOX_MODE_DO_NOT_USE,getInputElement:S,notFoundContent:g,class:h,popupClassName:e.popupClassName||e.dropdownClassName,ref:u},["dataSource","loading"]);return p(C,b,{default:()=>[c],...f(n,["default","dataSource","options"])})}}}),L=Object.assign(d,{Option:o,OptGroup:r,install(e){return e.component(d.name,d),e.component(o.displayName,o),e.component(r.displayName,r),e}});export{R as AutoCompleteOptGroup,z as AutoCompleteOption,M as autoCompleteProps,L as default};
