import{Fragment as _Fragment,jsx as _jsx}from"react/jsx-runtime";import{useCallback,memo,useEffect,useState,useMemo}from"react";import{useLocation}from"react-router-dom";import{removeLeadingSlash}from"@redocly/theme";const INITIAL_VISIBLE_ITEMS=3,BUFFER_ITEMS=1,FULL_LIST_DELAY=1e3,VirtualListComponent=({items:e=[],renderItem:t,routingBasePath:r})=>{const a=r||"/",o=useLocation(),n=removeLeadingSlash(o.pathname.replace(a,"")),s=useMemo((()=>{const t=new Map(e.map(((e,t)=>[removeLeadingSlash(e.href),t])));return e=>e?t.get(e):void 0}),[e]),m=useCallback((t=>{const r=s(t);return{start:Math.max(0,r?r-1:0),end:Math.min(e.length,r?r+1+1:3)}}),[s,e.length]),[i,u]=useState((()=>{const{start:t,end:r}=m(n);return e.slice(t,r)}));return useEffect((()=>{const t=setTimeout((()=>{u(e)}),1e3);return()=>clearTimeout(t)}),[e]),_jsx(_Fragment,{children:i.map(t)})};export const VirtualList=memo(VirtualListComponent);
//# sourceMappingURL=VirtualList.js.map