import { jsx as _jsx } from "react/jsx-runtime";
// (C) 2007-2025 GoodData Corporation
import { useCallback, useMemo } from "react";
import cx from "classnames";
import { pick } from "lodash-es";
import { guidFor } from "./guid.js";
import { LegacyList } from "./LegacyList.js";
import { LegacyListItem } from "./LegacyListItem.js";
import { LegacySingleSelectListItem } from "./LegacySingleSelectListItem.js";
/**
 * @internal
 * @deprecated This component is deprecated use SingleSelectList instead
 */
export function LegacySingleSelectList(props) {
    const { className = "", getItemKey = guidFor, items = [], itemsCount = 0, listItemClass = LegacySingleSelectListItem, onItemMouseOut = () => { }, onItemMouseOver = () => { }, onItemMouseEnter = () => { }, onItemMouseLeave = () => { }, onRangeChange = () => { }, onScrollStart = () => { }, onSelect = () => { }, rowItem = null, scrollToSelected = false, selection = {}, } = props;
    const getSelectableItems = useCallback(() => {
        return items.map((source) => ({
            source,
            onSelect,
            onMouseOver: onItemMouseOver,
            onMouseOut: onItemMouseOut,
            onMouseEnter: onItemMouseEnter,
            onMouseLeave: onItemMouseLeave,
            selected: source === selection,
            id: getItemKey(source),
        }));
    }, [
        items,
        onSelect,
        onItemMouseOver,
        onItemMouseOut,
        onItemMouseEnter,
        onItemMouseLeave,
        selection,
        getItemKey,
    ]);
    const classNames = useMemo(() => {
        return cx("gd-list", className);
    }, [className]);
    const rowItemElement = useMemo(() => {
        return rowItem || _jsx(LegacyListItem, { listItemClass: listItemClass });
    }, [rowItem, listItemClass]);
    const dataSource = useMemo(() => {
        const selectableItems = getSelectableItems();
        return {
            rowsCount: itemsCount || selectableItems.length,
            getObjectAt: (rowIndex) => selectableItems[rowIndex],
        };
    }, [itemsCount, getSelectableItems]);
    return (_jsx(LegacyList, { className: classNames, ...pick(props, ["width", "height", "itemHeight"]), dataSource: dataSource, rowItem: rowItemElement, onScroll: onRangeChange, onScrollStart: onScrollStart, scrollToSelected: scrollToSelected }));
}
