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