import React, { useRef } from "react";
import { useVirtualizer } from "@tanstack/react-virtual";
import { getHeightAsNumber } from "../../../../utils";
import { Item } from "../Inner/ui";
export const VirtualList = ({ items, listMaxHeight, onScroll })=>{
    const parentRef = useRef(null);
    const virtualizer = useVirtualizer({
        count: items.length,
        getScrollElement: ()=>parentRef.current,
        estimateSize: ()=>48
    });
    const virtualItems = virtualizer.getVirtualItems();
    return /*#__PURE__*/ React.createElement("div", {
        ref: parentRef,
        style: {
            height: 'auto',
            maxHeight: getHeightAsNumber(listMaxHeight),
            overflowY: 'auto'
        },
        onScroll: onScroll
    }, /*#__PURE__*/ React.createElement("div", {
        style: {
            height: virtualizer.getTotalSize(),
            width: '100%',
            position: 'relative'
        }
    }, /*#__PURE__*/ React.createElement("div", {
        style: {
            position: 'absolute',
            top: 0,
            left: 0,
            width: '100%',
            transform: `translateY(${virtualItems[0]?.start ?? 0}px)`
        }
    }, virtualItems.map((virtualRow)=>/*#__PURE__*/ React.createElement("div", {
            key: virtualRow.key,
            "data-index": virtualRow.index,
            ref: virtualizer.measureElement
        }, /*#__PURE__*/ React.createElement(Item, {
            item: items[virtualRow.index],
            path: [
                'root'
            ],
            currentLevel: 0,
            index: virtualRow.index,
            ariaLevel: 1
        }))))));
};
