1 "use strict";var k=Object.getOwnPropertySymbols;var T=Object.prototype.hasOwnProperty,z=Object.prototype.propertyIsEnumerable;var M=(e,n)=>{var l={};for(var a in e)T.call(e,a)&&n.indexOf(a)<0&&(l[a]=e[a]);if(e!=null&&k)for(var a of k(e))n.indexOf(a)<0&&z.call(e,a)&&(l[a]=e[a]);return l};var w=(e,n,l)=>new Promise((a,d)=>{var s=u=>{try{p(l.next(u))}catch(i){d(i)}},f=u=>{try{p(l.throw(u))}catch(i){d(i)}},p=u=>u.done?a(u.value):Promise.resolve(u.value).then(s,f);p((l=l.apply(e,n)).next())});const t=require("vue"),E=require("./CdxChipInput.cjs"),H=require("./CdxMenu.cjs"),P=require("./useFieldData.cjs"),j=require("./useFloatingMenu.cjs"),G=require("./useGeneratedId.cjs"),W=require("./useModelWrapper.cjs"),x=require("./useOptionalModelWrapper.js"),J=require("./useSplitAttributes.cjs"),b=require("./constants.js"),Q=require("./_plugin-vue_export-helper.js"),X=b.makeStringTypeValidator(b.ValidationStatusTypes),Y=t.defineComponent({name:"CdxMultiselectLookup",components:{CdxChipInput:E,CdxMenu:H},props:{inputChips:{type:Array,required:!0},selected:{type:[Array],required:!0},menuItems:{type:Array,required:!0},inputValue:{type:[String,Number],default:null},separateInput:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},readonly:{type:Boolean,default:!1},status:{type:String,default:"default",validator:X},menuConfig:{type:Object,default:()=>({})}},emits:["update:input-chips","update:selected","update:input-value","load-more","input","change","focus","blur"],setup:(e,{emit:n,attrs:l,slots:a})=>{const d=t.ref(),s=t.ref(),f=G("multiselect-lookup-menu"),p=t.computed(()=>{var o,r;return(r=(o=s.value)==null?void 0:o.getHighlightedMenuItem())==null?void 0:r.id}),u=t.ref(!1),i=t.ref(!1),h=t.ref(!1);t.provide(b.AllowArbitraryKey,t.ref(!1));const{computedDisabled:y,computedStatus:A}=P(t.toRef(e,"disabled"),t.toRef(e,"status")),B=t.computed(()=>({"cdx-multiselect-lookup--disabled":y.value,"cdx-multiselect-lookup--pending":u.value})),{rootClasses:R,rootStyle:U,otherAttrs:$}=J(l,B);j(d,s);const I=W(t.toRef(e,"selected"),n,"update:selected"),m=W(t.toRef(e,"inputChips"),n,"update:input-chips"),F=t.ref(""),g=x.useOptionalModelWrapper(F,t.toRef(e,"inputValue"),n,"update:input-value"),C=t.computed(()=>g.value.toString().length>0&&a["no-results"]);function K(o){return w(this,null,function*(){yield t.nextTick(),u.value=o!==null&&o!=="",n("input",o)})}function N(o){h.value=!0,(e.menuItems.length>0||C.value)&&(i.value=!0),n("focus",o)}function D(o){h.value=!1,i.value=!1,n("blur",o)}function L(o){!s.value||y.value||e.menuItems.length===0&&!C.value||o.key===" "||s.value.delegateKeyNavigation(o)}return t.watch(t.toRef(e,"selected"),o=>{const r=o.filter(v=>m.value.find(c=>v===c.value)===void 0);r.length>0&&(r.forEach(v=>{var q;const c=(q=s.value)==null?void 0:q.getComputedMenuItems().find(V=>V.value===v);if(c){const S=c,{id:V}=S,O=M(S,["id"]);m.value.push(O)}}),g.value="",n("input","")),m.value=m.value.filter(v=>o.find(c=>v.value===c)!==void 0)}),t.watch(t.toRef(e,"inputChips"),o=>{o.length<I.value.length&&(I.value=o.map(r=>r.value))}),t.watch(t.toRef(e,"menuItems"),o=>{o.length===0&&!C.value?i.value=!1:h.value&&u.value&&(i.value=!0),u.value=!1}),{chipInput:d,menu:s,menuId:f,highlightedId:p,expanded:i,computedDisabled:y,computedStatus:A,rootClasses:R,rootStyle:U,otherAttrs:$,selectedWrapper:I,inputChipsWrapper:m,computedInputValue:g,onUpdateInputValue:K,onInputBlur:D,onInputFocus:N,onKeydown:L}}});function Z(e,n,l,a,d,s){const f=t.resolveComponent("cdx-chip-input"),p=t.resolveComponent("cdx-menu");return t.openBlock(),t.createElementBlock("div",{class:t.normalizeClass(["cdx-multiselect-lookup",e.rootClasses]),style:t.normalizeStyle(e.rootStyle)},[t.createVNode(f,t.mergeProps({ref:"chipInput","input-chips":e.inputChipsWrapper,"onUpdate:inputChips":n[0]||(n[0]=u=>e.inputChipsWrapper=u),"input-value":e.computedInputValue,"onUpdate:inputValue":n[1]||(n[1]=u=>e.computedInputValue=u)},e.otherAttrs,{class:"cdx-multiselect-lookup__chip-input",role:"combobox",autocomplete:"off","aria-autocomplete":"list","aria-controls":e.menuId,"aria-expanded":e.expanded,"aria-activedescendant":e.highlightedId,"separate-input":e.separateInput,readonly:e.readonly,disabled:e.computedDisabled,status:e.computedStatus,"onUpdate:inputValue":e.onUpdateInputValue,onFocus:e.onInputFocus,onBlur:e.onInputBlur,onKeydown:e.onKeydown}),null,16,["input-chips","input-value","aria-controls","aria-expanded","aria-activedescendant","separate-input","readonly","disabled","status","onUpdate:inputValue","onFocus","onBlur","onKeydown"]),t.createVNode(p,t.mergeProps({id:e.menuId,ref:"menu",selected:e.selectedWrapper,"onUpdate:selected":n[2]||(n[2]=u=>e.selectedWrapper=u),expanded:e.expanded,"onUpdate:expanded":n[3]||(n[3]=u=>e.expanded=u),"menu-items":e.menuItems},e.menuConfig,{onLoadMore:n[4]||(n[4]=u=>e.$emit("load-more"))}),{default:t.withCtx(({menuItem:u})=>[t.renderSlot(e.$slots,"menu-item",{menuItem:u})]),"no-results":t.withCtx(()=>[t.renderSlot(e.$slots,"no-results")]),_:3},16,["id","selected","expanded","menu-items"])],6)}const _=Q._export_sfc(Y,[["render",Z]]);module.exports=_;