import{defineComponent as I,shallowRef as b,computed as T,createVNode as m}from"vue";import M from"@ant-design/icons-vue/SearchOutlined";import R from"lodash-es/isPlainObject";import _ from"../_util/classNames.mjs";import j from"../_util/omit.mjs";import{cloneElement as D}from"../_util/vnode.mjs";import U from"../_util/vue-types/index.mjs";import"../button/index.mjs";import V from"../config-provider/hooks/useConfigInject.mjs";import F from"./Input.mjs";import q from"./inputProps.mjs";import G from"../button/button.mjs";const rt=I({compatConfig:{MODE:3},name:"AInputSearch",inheritAttrs:!1,props:{...q(),inputPrefixCls:String,enterButton:U.any,onSearch:{type:Function}},setup(o,{slots:i,attrs:d,expose:x,emit:n}){const a=b(),c=b(!1);x({focus:()=>{a.value?.focus()},blur:()=>{a.value?.blur()}});const A=t=>{n("update:value",t.target.value),t&&t.target&&t.type==="click"&&n("search",t.target.value,t),n("change",t)},v=t=>{document.activeElement===a.value?.input&&t.preventDefault()},f=t=>{n("search",a.value?.input?.stateValue,t)},B=t=>{c.value||o.loading||f(t)},P=t=>{c.value=!0,n("compositionstart",t)},S=t=>{c.value=!1,n("compositionend",t)},{prefixCls:r,getPrefixCls:E,direction:O,size:s}=V("input-search",o),N=T(()=>E("input",o.inputPrefixCls));return()=>{const{disabled:t,loading:k,addonAfter:h=i.addonAfter?.(),suffix:$=i.suffix?.(),...w}=o;let{enterButton:e=i.enterButton?.()??!1}=o;e=e||e==="";const p=typeof e=="boolean"?m(M,null,null):null,C=`${r.value}-button`,l=Array.isArray(e)?e[0]:e;let u;const y=l.type&&R(l.type)&&l.type.__ANT_BUTTON;if(y||l.tagName==="button")u=D(l,{onMousedown:v,onClick:f,key:"enterButton",...y?{class:C,size:s.value}:{}},!1);else{const g=p&&!e;u=m(G,{class:C,type:e?"primary":void 0,size:s.value,disabled:t,key:"enterButton",onMousedown:v,onClick:f,loading:k,icon:g?p:null},{default:()=>[g?null:p||e]})}h&&(u=[u,h]);const z=_(r.value,{[`${r.value}-rtl`]:O.value==="rtl",[`${r.value}-${s.value}`]:!!s.value,[`${r.value}-with-button`]:!!e},d.class);return m(F,{ref:a,...j(w,["onUpdate:value","onSearch","enterButton"]),...d,onPressEnter:B,onCompositionstart:P,onCompositionend:S,size:s.value,prefixCls:N.value,addonAfter:u,suffix:$,onChange:A,class:z,disabled:t},i)}}});export{rt as default};
