1 "use strict";var b=Object.getOwnPropertySymbols;var K=Object.prototype.hasOwnProperty,w=Object.prototype.propertyIsEnumerable;var y=(e,n)=>{var u={};for(var o in e)K.call(e,o)&&n.indexOf(o)<0&&(u[o]=e[o]);if(e!=null&&b)for(var o of b(e))n.indexOf(o)<0&&w.call(e,o)&&(u[o]=e[o]);return u};const t=require("vue"),g=require("./Icon.js"),D=require("./CdxMenu.cjs"),C=require("./useGeneratedId.cjs"),H=require("./useModelWrapper.cjs"),W=require("./useFieldData.cjs"),j=require("./useSplitAttributes.cjs"),F=require("./useFloatingMenu.cjs"),p=require("./constants.js"),R=require("./_plugin-vue_export-helper.js"),T=p.makeStringTypeValidator(p.ValidationStatusTypes),z=t.defineComponent({name:"CdxSelect",components:{CdxIcon:g.CdxIcon,CdxMenu:D},inheritAttrs:!1,props:{menuItems:{type:Array,required:!0},selected:{type:[String,Number,null],required:!0},defaultLabel:{type:String,default:""},disabled:{type:Boolean,default:!1},menuConfig:{type:Object,default:()=>({})},defaultIcon:{type:[String,Object],default:void 0},status:{type:String,default:"default",validator:T}},emits:["update:selected","load-more"],setup(e,{emit:n,attrs:u}){const o=t.ref(),i=t.ref(),v=t.inject(p.FieldDescriptionIdKey,void 0),m=C("select-menu"),r=t.ref(!1),l=u.id||C("select-handle"),{computedDisabled:c,computedStatus:S,computedInputId:h}=W(t.toRef(e,"disabled"),t.toRef(e,"status"),l),q=H(t.toRef(e,"selected"),n,"update:selected"),a=t.computed(()=>{var d;return(d=i.value)==null?void 0:d.getComputedMenuItems().find(s=>s.value===e.selected)}),x=t.computed(()=>{var d;return a.value?(d=a.value.label)!=null?d:a.value.value:e.defaultLabel}),f=t.computed(()=>{var d;if(e.defaultIcon&&!a.value)return e.defaultIcon;if((d=a.value)!=null&&d.icon)return a.value.icon}),M=t.computed(()=>({"cdx-select-vue--enabled":!c.value,"cdx-select-vue--disabled":c.value,"cdx-select-vue--expanded":r.value,"cdx-select-vue--value-selected":!!a.value,"cdx-select-vue--no-selections":!a.value,"cdx-select-vue--has-start-icon":!!f.value,["cdx-select-vue--status-".concat(S.value)]:!0})),{rootClasses:k,rootStyle:B,otherAttrs:V}=j(u,M),$=t.computed(()=>{const I=V.value,{id:d}=I;return y(I,["id"])}),N=t.computed(()=>{var d,s;return(s=(d=i.value)==null?void 0:d.getHighlightedMenuItem())==null?void 0:s.id});function L(){r.value=!1}function A(){var d;c.value||(r.value=!r.value,(d=o.value)==null||d.focus())}function E(d){var s;c.value||(s=i.value)==null||s.delegateKeyNavigation(d,{characterNavigation:!0})}return F(o,i),{handle:o,menu:i,computedHandleId:h,descriptionId:v,menuId:m,modelWrapper:q,selectedMenuItem:a,highlightedId:N,expanded:r,computedDisabled:c,onBlur:L,currentLabel:x,rootClasses:k,rootStyle:B,otherAttrsMinusId:$,onClick:A,onKeydown:E,startIcon:f,cdxIconExpand:g.M4}}}),O=["aria-disabled"],P=["id","aria-controls","aria-activedescendant","aria-expanded","aria-describedby"];function U(e,n,u,o,i,v){const m=t.resolveComponent("cdx-icon"),r=t.resolveComponent("cdx-menu");return t.openBlock(),t.createElementBlock("div",{class:t.normalizeClass(["cdx-select-vue",e.rootClasses]),style:t.normalizeStyle(e.rootStyle),"aria-disabled":e.computedDisabled},[t.createElementVNode("div",t.mergeProps({id:e.computedHandleId,ref:"handle",class:"cdx-select-vue__handle"},e.otherAttrsMinusId,{tabindex:"0",role:"combobox","aria-controls":e.menuId,"aria-activedescendant":e.highlightedId,"aria-expanded":e.expanded,"aria-describedby":e.descriptionId,onClick:n[0]||(n[0]=(...l)=>e.onClick&&e.onClick(...l)),onBlur:n[1]||(n[1]=(...l)=>e.onBlur&&e.onBlur(...l)),onKeydown:n[2]||(n[2]=(...l)=>e.onKeydown&&e.onKeydown(...l))}),[t.renderSlot(e.$slots,"label",{selectedMenuItem:e.selectedMenuItem,defaultLabel:e.defaultLabel},()=>[t.createTextVNode(t.toDisplayString(e.currentLabel),1)]),e.startIcon?(t.openBlock(),t.createBlock(m,{key:0,icon:e.startIcon,class:"cdx-select-vue__start-icon"},null,8,["icon"])):t.createCommentVNode("v-if",!0),t.createVNode(m,{icon:e.cdxIconExpand,class:"cdx-select-vue__indicator"},null,8,["icon"])],16,P),t.createVNode(r,t.mergeProps({id:e.menuId,ref:"menu",selected:e.modelWrapper,"onUpdate:selected":n[3]||(n[3]=l=>e.modelWrapper=l),expanded:e.expanded,"onUpdate:expanded":n[4]||(n[4]=l=>e.expanded=l),"menu-items":e.menuItems},e.menuConfig,{onLoadMore:n[5]||(n[5]=l=>e.$emit("load-more"))}),{default:t.withCtx(({menuItem:l})=>[t.renderSlot(e.$slots,"menu-item",{menuItem:l})]),_:3},16,["id","selected","expanded","menu-items"])],14,O)}const G=R._export_sfc(z,[["render",U]]);module.exports=G;