"use strict";const e=require("vue"),g=require("./CdxLabel.cjs"),y=require("./CdxMessage.cjs"),s=require("./constants.js"),a=require("./useGeneratedId.cjs"),C=require("./useComputedDisabled.cjs"),h=require("./_plugin-vue_export-helper.js"),I=s.makeStringTypeValidator(s.ValidationStatusTypes),F=e.defineComponent({name:"CdxField",components:{CdxLabel:g,CdxMessage:y},props:{labelIcon:{type:[String,Object],default:""},optional:{type:Boolean,default:!1},optionalFlag:{type:String,default:""},hideLabel:{type:Boolean,default:!1},isFieldset:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},status:{type:String,default:"default",validator:I},messages:{type:Object,default:()=>({})}},setup(t,{slots:n}){const{disabled:r,status:u,isFieldset:d}=e.toRefs(t),i=C(r),o=e.computed(()=>({"cdx-field--disabled":i.value,"cdx-field--is-fieldset":d.value})),l=a("label"),c=a("description"),p=a("input"),f=e.computed(()=>d.value?void 0:p);e.provide(s.FieldInputIdKey,f);const m=e.computed(()=>!d.value&&n.description?c:void 0);e.provide(s.FieldDescriptionIdKey,m),e.provide(s.DisabledKey,i),e.provide(s.FieldStatusKey,u);const v=e.computed(()=>t.status!=="default"&&t.status in t.messages?t.messages[t.status]:""),b=e.computed(()=>t.status==="default"?"notice":t.status);return{rootClasses:o,computedDisabled:i,labelId:l,descriptionId:c,inputId:p,validationMessage:v,validationMessageType:b}}}),S={class:"cdx-field__control"},D={class:"cdx-field__help-text"},V={key:0,class:"cdx-field__validation-message"};function $(t,n,r,u,d,i){const o=e.resolveComponent("cdx-label"),l=e.resolveComponent("cdx-message");return e.openBlock(),e.createBlock(e.resolveDynamicComponent(t.isFieldset?"fieldset":"div"),{class:e.normalizeClass(["cdx-field",t.rootClasses]),"aria-disabled":!t.isFieldset&&t.computedDisabled?!0:void 0,disabled:t.isFieldset&&t.computedDisabled?!0:void 0},{default:e.withCtx(()=>[e.createVNode(o,{id:t.labelId,icon:t.labelIcon,"visually-hidden":t.hideLabel,optional:t.optional,"optional-flag":t.optionalFlag,"input-id":t.inputId,"description-id":t.descriptionId,disabled:t.computedDisabled,"is-legend":t.isFieldset},e.createSlots({default:e.withCtx(()=>[e.renderSlot(t.$slots,"label")]),_:2},[t.$slots.description&&t.$slots.description().length>0?{name:"description",fn:e.withCtx(()=>[e.renderSlot(t.$slots,"description")]),key:"0"}:void 0]),1032,["id","icon","visually-hidden","optional","optional-flag","input-id","description-id","disabled","is-legend"]),e.createElementVNode("div",S,[e.renderSlot(t.$slots,"default")]),e.createElementVNode("div",D,[e.renderSlot(t.$slots,"help-text")]),!t.computedDisabled&&t.validationMessage?(e.openBlock(),e.createElementBlock("div",V,[e.createVNode(l,{type:t.validationMessageType,inline:!0},{default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(t.validationMessage),1)]),_:1},8,["type"])])):e.createCommentVNode("v-if",!0)]),_:3},8,["class","aria-disabled","disabled"])}const B=h._export_sfc(F,[["render",$]]);module.exports=B;
