"use strict";const t=require("vue"),A=require("./CdxMenu.cjs"),F=require("./CdxTextInput.cjs"),K=require("./useGeneratedId.cjs"),N=require("./useModelWrapper.cjs"),w=require("./useSplitAttributes.cjs"),L=require("./useFieldData.cjs"),W=require("./useFloatingMenu.cjs"),b=require("./constants.js"),D=require("./_plugin-vue_export-helper.js");require("./CdxMenuItem.cjs");require("./Icon.js");require("./useComputedDirection.cjs");require("./useComputedLanguage.cjs");require("./CdxThumbnail.cjs");require("./CdxSearchResultTitle.cjs");require("./CdxProgressBar.cjs");require("./useWarnOnce.cjs");require("./useIntersectionObserver.cjs");require("./useComputedDisabled.cjs");const E=b.makeStringTypeValidator(b.ValidationStatusTypes),P=t.defineComponent({name:"CdxLookup",components:{CdxMenu:A,CdxTextInput:F},inheritAttrs:!1,props:{selected:{type:[String,Number,null],required:!0},menuItems:{type:Array,required:!0},initialInputValue:{type:[String,Number],default:""},disabled:{type:Boolean,default:!1},menuConfig:{type:Object,default:()=>({})},status:{type:String,default:"default",validator:E}},emits:["update:selected","load-more","input","change","focus","blur"],setup:(e,{emit:u,attrs:g,slots:i})=>{const I=t.ref(),p=t.ref(),l=t.ref(),m=K("lookup-menu"),o=t.ref(!1),s=t.ref(!1),c=t.ref(!1),q=t.ref(e.menuItems),{computedDisabled:f}=L(t.toRef(e,"disabled")),y=t.toRef(e,"selected"),h=N(y,u,"update:selected"),r=t.computed(()=>e.menuItems.find(n=>n.value===e.selected)),C=t.computed(()=>{var n,a;return(a=(n=l.value)==null?void 0:n.getHighlightedMenuItem())==null?void 0:a.id}),d=t.ref(e.initialInputValue),V=t.computed(()=>({"cdx-lookup--disabled":f.value,"cdx-lookup--pending":o.value})),{rootClasses:k,rootStyle:S,otherAttrs:M}=w(g,V);function $(n){r.value&&r.value.label!==n&&r.value.value!==n&&(h.value=null),n===""&&q.value.length===0?(s.value=!1,o.value=!1):o.value=!0,u("input",n)}function x(n){c.value=!0;const a=d.value!==null&&d.value!=="";!!(e.menuItems.length>0||i["no-results"])&&(a||q.value.length>0)&&(s.value=!0),u("focus",n)}function B(n){c.value=!1,s.value=!1,u("blur",n)}function U(n){!l.value||f.value||e.menuItems.length===0&&!i["no-results"]||n.key===" "||l.value.delegateKeyNavigation(n)}return W(p,l),t.watch(y,n=>{var a;if(n!==null){const v=r.value?(a=r.value.label)!=null?a:r.value.value:"";d.value!==v&&(d.value=v,u("input",d.value))}}),t.watch(t.toRef(e,"menuItems"),n=>{c.value&&o.value&&(n.length>0||i["no-results"])&&(s.value=!0),n.length===0&&!i["no-results"]&&(s.value=!1),o.value=!1}),{rootElement:I,textInput:p,menu:l,menuId:m,highlightedId:C,inputValue:d,modelWrapper:h,expanded:s,computedDisabled:f,onInputBlur:B,rootClasses:k,rootStyle:S,otherAttrs:M,onUpdateInput:$,onInputFocus:x,onKeydown:U}}});function R(e,u,g,i,I,p){const l=t.resolveComponent("cdx-text-input"),m=t.resolveComponent("cdx-menu");return t.openBlock(),t.createElementBlock("div",{ref:"rootElement",class:t.normalizeClass(["cdx-lookup",e.rootClasses]),style:t.normalizeStyle(e.rootStyle)},[t.createVNode(l,t.mergeProps({ref:"textInput",modelValue:e.inputValue,"onUpdate:modelValue":u[0]||(u[0]=o=>e.inputValue=o)},e.otherAttrs,{class:"cdx-lookup__input",role:"combobox",autocomplete:"off","aria-autocomplete":"list","aria-controls":e.menuId,"aria-expanded":e.expanded,"aria-activedescendant":e.highlightedId,disabled:e.computedDisabled,status:e.status,"onUpdate:modelValue":e.onUpdateInput,onChange:u[1]||(u[1]=o=>e.$emit("change",o)),onFocus:e.onInputFocus,onBlur:e.onInputBlur,onKeydown:e.onKeydown}),null,16,["modelValue","aria-controls","aria-expanded","aria-activedescendant","disabled","status","onUpdate:modelValue","onFocus","onBlur","onKeydown"]),t.createVNode(m,t.mergeProps({id:e.menuId,ref:"menu",selected:e.modelWrapper,"onUpdate:selected":u[2]||(u[2]=o=>e.modelWrapper=o),expanded:e.expanded,"onUpdate:expanded":u[3]||(u[3]=o=>e.expanded=o),"menu-items":e.menuItems},e.menuConfig,{onLoadMore:u[4]||(u[4]=o=>e.$emit("load-more"))}),{default:t.withCtx(({menuItem:o})=>[t.renderSlot(e.$slots,"menu-item",{menuItem:o})]),"no-results":t.withCtx(()=>[t.renderSlot(e.$slots,"no-results")]),_:3},16,["id","selected","expanded","menu-items"])],6)}const T=D._export_sfc(P,[["render",R]]);module.exports=T;
