"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const n=require("vue"),c=require("../_util/KeyCode.js"),F=require("../_util/classNames.js"),te=require("../_util/createRef.js"),oe=require("../_util/hooks/useMemo.js"),ne=require("../_util/omit.js"),le=require("../_util/pickAttrs.js"),se=require("../_util/props-util/index.js"),ie=require("../vc-virtual-list/List.js"),ae=require("./SelectContext.js"),ce=require("./TransBtn.js"),re=require("./hooks/useBaseProps.js"),ue=require("./utils/platformUtil.js");function H(I){return typeof I=="string"||typeof I=="number"}const de=n.defineComponent({compatConfig:{MODE:3},name:"OptionList",inheritAttrs:!1,setup(I,{expose:R,slots:z}){const l=re.default(),i=ae.default(),d=n.computed(()=>`${l.prefixCls}-item`),r=oe.default(()=>i.flattenOptions,[()=>l.open,()=>i.flattenOptions],e=>e[0]),V=te.default(),L=e=>{e.preventDefault()},$=e=>{V.current&&V.current.scrollTo(typeof e=="number"?{index:e}:e)},k=(e,o=1)=>{const s=r.value.length;for(let t=0;t<s;t+=1){const a=(e+t*o+s)%s,{group:m,data:f}=r.value[a];if(!m&&!f.disabled)return a}return-1},N=n.reactive({activeIndex:k(0)}),w=(e,o=!1)=>{N.activeIndex=e;const s={source:o?"keyboard":"mouse"},t=r.value[e];if(!t){i.onActiveValue(null,-1,s);return}i.onActiveValue(t.value,e,s)};n.watch([()=>r.value.length,()=>l.searchValue],()=>{w(i.defaultActiveFirstOption!==!1?k(0):-1)},{immediate:!0});const D=e=>i.rawValues.has(e)&&l.mode!=="combobox";n.watch([()=>l.open,()=>l.searchValue],()=>{if(!l.multiple&&l.open&&i.rawValues.size===1){const e=Array.from(i.rawValues)[0],o=n.toRaw(r.value).findIndex(({data:s})=>s[i.fieldNames.value]===e);o!==-1&&(w(o),n.nextTick(()=>{$(o)}))}l.open&&n.nextTick(()=>{V.current?.scrollTo(void 0)})},{immediate:!0,flush:"post"});const q=e=>{e!==void 0&&i.onSelect(e,{selected:!i.rawValues.has(e)}),l.multiple||l.toggleOpen(!1)},K=e=>typeof e.label=="function"?e.label():e.label;function C(e){const o=r.value[e];if(!o)return null;const s=o.data||{},{value:t}=s,{group:a}=o,m=le.default(s,!0),f=K(o);return o?n.createVNode("div",{"aria-label":typeof f=="string"&&!a?f:null,...m,key:e,role:a?"presentation":"option",id:`${l.id}_list_${e}`,"aria-selected":D(t)},[t]):null}return R({onKeydown:e=>{const{which:o,ctrlKey:s}=e;switch(o){case c.default.N:case c.default.P:case c.default.UP:case c.default.DOWN:{let t=0;if(o===c.default.UP?t=-1:o===c.default.DOWN?t=1:ue.isPlatformMac()&&s&&(o===c.default.N?t=1:o===c.default.P&&(t=-1)),t!==0){const a=k(N.activeIndex+t,t);$(a),w(a,!0)}break}case c.default.ENTER:{const t=r.value[N.activeIndex];t&&!t.data.disabled?q(t.value):q(void 0),l.open&&e.preventDefault();break}case c.default.ESC:l.toggleOpen(!1),l.open&&e.stopPropagation()}},onKeyup:()=>{},scrollTo:e=>{$(e)}}),()=>{const{id:e,notFoundContent:o,onPopupScroll:s}=l,{menuItemSelectedIcon:t,fieldNames:a,virtual:m,listHeight:f,listItemHeight:U}=i,x=z.option,{activeIndex:b}=N,j=Object.keys(a).map(u=>a[u]);return r.value.length===0?n.createVNode("div",{role:"listbox",id:`${e}_list`,class:`${d.value}-empty`,onMousedown:L},[o]):n.createVNode(n.Fragment,null,[n.createVNode("div",{role:"listbox",id:`${e}_list`,style:{height:0,width:0,overflow:"hidden"}},[C(b-1),C(b),C(b+1)]),n.createVNode(ie.default,{itemKey:"key",ref:V,data:r.value,height:f,itemHeight:U,fullHeight:!1,onMousedown:L,onScroll:s,virtual:m},{default:(u,T)=>{const{group:B,groupOption:W,data:g,value:S}=u,{key:G}=g,O=typeof u.label=="function"?u.label():u.label;if(B){const h=g.title??(H(O)&&O);return n.createVNode("div",{class:F.default(d.value,`${d.value}-group`),title:h},[x?x(g):O!==void 0?O:G])}const{disabled:P,title:_,children:me,style:J,class:Q,className:X,...y}=g,Y=ne.default(y,j),p=D(S),v=`${d.value}-option`,Z=F.default(d.value,v,Q,X,{[`${v}-grouped`]:W,[`${v}-active`]:b===T&&!P,[`${v}-disabled`]:P,[`${v}-selected`]:p}),M=K(u),ee=!t||typeof t=="function"||p,A=typeof M=="number"?M:M||S;let E=H(A)?A.toString():void 0;return _!==void 0&&(E=_),n.createVNode("div",{...Y,"aria-selected":p,class:Z,title:E,onMousemove:h=>{y.onMousemove&&y.onMousemove(h),!(b===T||P)&&w(T)},onClick:h=>{P||q(S),y.onClick&&y.onClick(h)},style:J},[n.createVNode("div",{class:`${v}-content`},[x?x(g):A]),se.isValidElement(t)||p,ee&&n.createVNode(ce.default,{class:`${d.value}-option-state`,customizeIcon:t,customizeIconProps:{isSelected:p}},{default:()=>[p?"✓":null]})])}})])}}});exports.default=de;
