import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { bem } from "../@ui/@utils/bem.js";
import { LoadingSpinner } from "../LoadingSpinner/LoadingSpinner.js";
import { CatalogItemPickerFooter, CatalogItemPickerList, CatalogItemPickerSearch, CatalogItemPickerTabs, } from "./CatalogItemPickerParts.js";
import { testIds } from "./messages.js";
const { b, e } = bem("gd-ui-kit-catalog-item-picker");
/**
 * The reusable inner part of the catalog item picker: the picker root, an optional header slot, search,
 * optional type tabs, the grouped list and (in multi-select mode) the footer. Driven by a
 * {@link useCatalogItemPicker} controller so it can be reused outside the full {@link CatalogItemPicker}
 * — e.g. embedded in the ranking filter measure dropdown, which provides its own anchor button instead
 * of the picker header.
 *
 * @internal
 */
export function CatalogItemPickerBody({ controller, maxListHeight, onClose, header, }) {
    const { variant, selectionMode, isLoading, searchString, handleSearchChange, handleSearchEscKeyPress, labels, showTabs, resolvedItemTypes, effectiveType, handleTabChange, listboxItems, isMultiSelect, listboxId, shouldShowEmptyStateMessage, emptyMessage, handleListboxSelect, isAddDisabled, handleAdd, } = controller;
    return (_jsxs("div", { className: b({ variant, selectionMode }), "data-testid": testIds.root, children: [header, _jsx("div", { className: e("content", { variant }), children: isLoading ? (_jsx("div", { className: e("loading", { variant }), children: _jsx(LoadingSpinner, { className: "small" }) })) : (_jsxs(_Fragment, { children: [
                        _jsx(CatalogItemPickerSearch, { variant: variant, value: searchString, onChange: handleSearchChange, onEscKeyPress: handleSearchEscKeyPress, placeholder: labels.searchPlaceholder, ariaLabel: labels.searchAriaLabel }), showTabs ? (_jsx(CatalogItemPickerTabs, { variant: variant, itemTypes: resolvedItemTypes, effectiveType: effectiveType, onChange: handleTabChange, getAriaLabel: (type) => labels.tabLabels?.[type] ?? labels.title })) : null, _jsx(CatalogItemPickerList, { variant: variant, listboxItems: listboxItems, isMultiSelect: isMultiSelect, maxListHeight: maxListHeight, listboxId: listboxId, ariaLabel: labels.title, shouldShowEmptyStateMessage: shouldShowEmptyStateMessage, emptyMessage: emptyMessage, onSelect: handleListboxSelect })
                    ] })) }), isMultiSelect ? (_jsx(CatalogItemPickerFooter, { variant: variant, isAddDisabled: isAddDisabled, onClose: onClose, onAdd: handleAdd, cancelLabel: labels.cancelLabel, addLabel: labels.addLabel ?? "", addTooltip: labels.addTooltip })) : null] }));
}
