"use strict";var b=Object.getOwnPropertySymbols;var E=Object.prototype.hasOwnProperty,K=Object.prototype.propertyIsEnumerable;var y=(e,n)=>{var u={};for(var o in e)E.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&&K.call(e,o)&&(u[o]=e[o]);return u};const t=require("vue"),g=require("./Icon.js"),w=require("./CdxMenu.cjs"),D=require("./useModelWrapper.cjs"),H=require("./useFieldData.cjs"),W=require("./useSplitAttributes.cjs"),j=require("./useFloatingMenu.cjs"),p=require("./constants.js"),F=require("./_plugin-vue_export-helper.js"),R=p.makeStringTypeValidator(p.ValidationStatusTypes),T=t.defineComponent({name:"CdxSelect",components:{CdxIcon:g.CdxIcon,CdxMenu:w},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:R}},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=t.useId(),r=t.ref(!1),l=u.id||t.useId(),{computedDisabled:c,computedStatus:C,computedInputId:S}=H(t.toRef(e,"disabled"),t.toRef(e,"status"),l),h=D(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}),q=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(C.value)]:!0})),{rootClasses:M,rootStyle:k,otherAttrs:B}=W(u,q),V=t.computed(()=>{const I=B.value,{id:d}=I;return y(I,["id"])}),$=t.computed(()=>{var d,s;return(s=(d=i.value)==null?void 0:d.getHighlightedMenuItem())==null?void 0:s.id});function N(){r.value=!1}function L(){var d;c.value||(r.value=!r.value,(d=o.value)==null||d.focus())}function A(d){var s;c.value||(s=i.value)==null||s.delegateKeyNavigation(d,{characterNavigation:!0})}return j(o,i),{handle:o,menu:i,computedHandleId:S,descriptionId:v,menuId:m,modelWrapper:h,selectedMenuItem:a,highlightedId:$,expanded:r,computedDisabled:c,onBlur:N,currentLabel:x,rootClasses:M,rootStyle:k,otherAttrsMinusId:V,onClick:L,onKeydown:A,startIcon:f,cdxIconExpand:g.u4}}}),z=["aria-disabled"],O=["id","aria-controls","aria-activedescendant","aria-expanded","aria-describedby"];function P(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,O),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,z)}const U=F._export_sfc(T,[["render",P]]);module.exports=U;
