"use strict";const t=require("vue"),b=require("./Icon.js"),m=require("./CdxButton.cjs"),h=require("./CdxTextInput.cjs"),f=require("./useModelWrapper.cjs"),S=require("./useSplitAttributes.cjs"),y=require("./useFieldData.cjs"),B=require("./useI18nWithOverride.js"),i=require("./constants.js"),C=require("./_plugin-vue_export-helper.js"),I=i.makeStringTypeValidator(i.ValidationStatusTypes),V=t.defineComponent({name:"CdxSearchInput",components:{CdxButton:m,CdxTextInput:h},inheritAttrs:!1,props:{modelValue:{type:[String,Number],default:""},useButton:{type:Boolean,default:!1},hideIcon:{type:Boolean,default:!1},clearable:{type:Boolean,default:!1},buttonLabel:{type:String,default:"",validator:(e,o)=>e.length>0&&!o.useButton?(console.warn("[CdxSearchInput]: The boolean `useButton` prop is required to show the search button.\n\nRefer to https://doc.wikimedia.org/codex/latest/components/demos/search-input.html#props."),!1):!0},disabled:{type:Boolean,default:!1},status:{type:String,default:"default",validator:I}},emits:["update:modelValue","submit-click","input","change","focus","blur"],setup(e,{emit:o,attrs:r}){const s=f(t.toRef(e,"modelValue"),o),{computedDisabled:l}=y(t.toRef(e,"disabled")),d=t.computed(()=>({"cdx-search-input--has-end-button":!!e.buttonLabel||e.useButton})),{rootClasses:a,rootStyle:u,otherAttrs:n}=S(r,d),c=B.useI18nWithOverride(t.toRef(e,"buttonLabel"),"cdx-search-input-search-button-label","Search"),p=t.computed(()=>e.useButton||e.buttonLabel.length>0);return{wrappedModel:s,computedDisabled:l,rootClasses:a,rootStyle:u,otherAttrs:n,handleSubmit:()=>{o("submit-click",s.value)},searchIcon:b.E7,translatedSearchButtonLabel:c,useButtonOrLabel:p}},methods:{focus(){this.$refs.textInput.focus()}}}),g={class:"cdx-search-input__input-wrapper"};function v(e,o,r,s,l,d){const a=t.resolveComponent("cdx-text-input"),u=t.resolveComponent("cdx-button");return t.openBlock(),t.createElementBlock("div",{class:t.normalizeClass(["cdx-search-input",e.rootClasses]),style:t.normalizeStyle(e.rootStyle)},[t.createElementVNode("div",g,[t.createVNode(a,t.mergeProps({ref:"textInput",modelValue:e.wrappedModel,"onUpdate:modelValue":o[0]||(o[0]=n=>e.wrappedModel=n),class:"cdx-search-input__text-input","input-type":"search","start-icon":e.hideIcon?void 0:e.searchIcon,clearable:e.clearable,disabled:e.computedDisabled,status:e.status},e.otherAttrs,{onKeydown:t.withKeys(e.handleSubmit,["enter"]),onInput:o[1]||(o[1]=n=>e.$emit("input",n)),onChange:o[2]||(o[2]=n=>e.$emit("change",n)),onFocus:o[3]||(o[3]=n=>e.$emit("focus",n)),onBlur:o[4]||(o[4]=n=>e.$emit("blur",n))}),null,16,["modelValue","start-icon","clearable","disabled","status","onKeydown"]),t.renderSlot(e.$slots,"default")]),e.useButtonOrLabel?(t.openBlock(),t.createBlock(u,{key:0,class:"cdx-search-input__end-button",disabled:e.computedDisabled,onClick:e.handleSubmit},{default:t.withCtx(()=>[t.createTextVNode(t.toDisplayString(e.translatedSearchButtonLabel),1)]),_:1},8,["disabled","onClick"])):t.createCommentVNode("v-if",!0)],6)}const k=C._export_sfc(V,[["render",v]]);module.exports=k;
