import React, { useRef } from "react";
import { useVirtualizer } from "@tanstack/react-virtual";
import { getHeightAsNumber } from "../../../../../utils";
import { Item } from "../Inner/ui";
export var VirtualList = function VirtualList(param) {
    var items = param.items, listMaxHeight = param.listMaxHeight, onScroll = param.onScroll;
    var _ref;
    var _virtualItems_;
    var parentRef = useRef(null);
    var virtualizer = useVirtualizer({
        count: items.length,
        getScrollElement: function getScrollElement() {
            return parentRef.current;
        },
        estimateSize: function estimateSize() {
            return 48;
        }
    });
    var 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(".concat((_ref = (_virtualItems_ = virtualItems[0]) === null || _virtualItems_ === void 0 ? void 0 : _virtualItems_.start) !== null && _ref !== void 0 ? _ref : 0, "px)")
        }
    }, virtualItems.map(function(virtualRow) {
        return /*#__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
        }));
    }))));
};
