1 "use strict";var I=Object.getOwnPropertySymbols;var M=Object.prototype.hasOwnProperty,q=Object.prototype.propertyIsEnumerable;var v=(e,t)=>{var u={};for(var s in e)M.call(e,s)&&t.indexOf(s)<0&&(u[s]=e[s]);if(e!=null&&I)for(var s of I(e))t.indexOf(s)<0&&q.call(e,s)&&(u[s]=e[s]);return u};const n=require("vue"),C=require("./Icon.js"),r=require("./constants.js"),K=require("./useModelWrapper.cjs"),A=require("./useSplitAttributes.cjs"),F=require("./useFieldData.cjs"),E=require("./_plugin-vue_export-helper.js"),N=r.makeStringTypeValidator(r.TextInputTypes),j=r.makeStringTypeValidator(r.ValidationStatusTypes),P=n.defineComponent({name:"CdxTextInput",components:{CdxIcon:C.CdxIcon},inheritAttrs:!1,expose:["focus","blur","checkValidity","reportValidity","setCustomValidity"],props:{modelValue:{type:[String,Number],default:""},inputType:{type:String,default:"text",validator:N},status:{type:String,default:"default",validator:j},disabled:{type:Boolean,default:!1},startIcon:{type:[String,Object],default:void 0},endIcon:{type:[String,Object],default:void 0},clearable:{type:Boolean,default:!1}},emits:["update:modelValue","keydown","input","change","focus","blur","clear","invalid"],setup(e,{emit:t,attrs:u}){const s=u.id,{computedDisabled:a,computedStatus:p,computedInputId:l}=F(n.toRef(e,"disabled"),n.toRef(e,"status"),s),i=n.inject(r.FieldDescriptionIdKey,void 0),d=K(n.toRef(e,"modelValue"),t),c=n.computed(()=>e.clearable&&!!d.value&&!a.value),b=n.computed(()=>({"cdx-text-input--has-start-icon":!!e.startIcon,"cdx-text-input--has-end-icon":!!e.endIcon,"cdx-text-input--clearable":c.value,["cdx-text-input--status-".concat(p.value)]:!0})),{rootClasses:V,rootStyle:k,otherAttrs:g}=A(u,b),h=n.computed(()=>{const m=g.value,{id:o}=m;return v(m,["id"])}),x=n.computed(()=>({"cdx-text-input__input--has-value":!!d.value})),B=o=>{d.value="",t("clear",o)},S=o=>{(o.key==="Home"||o.key==="End")&&!o.ctrlKey&&!o.metaKey||t("keydown",o)},w=o=>{t("input",o)},D=o=>{t("change",o)},T=o=>{t("focus",o)},$=o=>{t("blur",o)},y=n.ref(!0);return{computedInputId:l,descriptionId:i,wrappedModel:d,isClearable:c,rootClasses:V,rootStyle:k,otherAttrsMinusId:h,inputClasses:x,computedDisabled:a,onClear:B,onInput:w,onChange:D,onKeydown:S,onFocus:T,onBlur:$,onInvalid:(o,f)=>{f&&o.preventDefault(),t("invalid",o),y.value=!0},shouldPreventDefault:y,cdxIconClear:C.j3}},methods:{focus(){this.$refs.input.focus()},blur(){this.$refs.input.blur()},checkValidity(){return this.$refs.input.checkValidity()},reportValidity(){return this.shouldPreventDefault=!1,this.$refs.input.reportValidity()},setCustomValidity(e){this.$refs.input.setCustomValidity(e)}}}),z=["id","type","aria-describedby","disabled"];function R(e,t,u,s,a,p){const l=n.resolveComponent("cdx-icon");return n.openBlock(),n.createElementBlock("div",{class:n.normalizeClass(["cdx-text-input",e.rootClasses]),style:n.normalizeStyle(e.rootStyle)},[n.withDirectives(n.createElementVNode("input",n.mergeProps({id:e.computedInputId,ref:"input","onUpdate:modelValue":t[0]||(t[0]=i=>e.wrappedModel=i),class:["cdx-text-input__input",e.inputClasses]},e.otherAttrsMinusId,{type:e.inputType,"aria-describedby":e.descriptionId,disabled:e.computedDisabled,size:"1",onInput:t[1]||(t[1]=(...i)=>e.onInput&&e.onInput(...i)),onChange:t[2]||(t[2]=(...i)=>e.onChange&&e.onChange(...i)),onFocus:t[3]||(t[3]=(...i)=>e.onFocus&&e.onFocus(...i)),onBlur:t[4]||(t[4]=(...i)=>e.onBlur&&e.onBlur(...i)),onKeydown:t[5]||(t[5]=(...i)=>e.onKeydown&&e.onKeydown(...i)),onInvalid:t[6]||(t[6]=i=>e.onInvalid(i,e.shouldPreventDefault))}),null,16,z),[[n.vModelDynamic,e.wrappedModel]]),e.startIcon?(n.openBlock(),n.createBlock(l,{key:0,icon:e.startIcon,class:"cdx-text-input__icon-vue cdx-text-input__start-icon"},null,8,["icon"])):n.createCommentVNode("v-if",!0),e.endIcon?(n.openBlock(),n.createBlock(l,{key:1,icon:e.endIcon,class:"cdx-text-input__icon-vue cdx-text-input__end-icon"},null,8,["icon"])):n.createCommentVNode("v-if",!0),e.isClearable?(n.openBlock(),n.createBlock(l,{key:2,icon:e.cdxIconClear,class:"cdx-text-input__icon-vue cdx-text-input__clear-icon",onMousedown:t[7]||(t[7]=n.withModifiers(()=>{},["prevent"])),onClick:e.onClear},null,8,["icon","onClick"])):n.createCommentVNode("v-if",!0)],6)}const H=E._export_sfc(P,[["render",R]]);module.exports=H;