import { jsx as _jsx } from "react/jsx-runtime";
// (C) 2023-2025 GoodData Corporation
import { useState } from "react";
import { useIntl } from "react-intl";
import { messages } from "@gooddata/sdk-ui";
import { DropdownList, SingleSelectListItem } from "@gooddata/sdk-ui-kit";
import { CatalogAttributeDataType } from "./types.js";
import { searchAttributes } from "./utils.js";
const DEFAULT_DROPDOWN_WIDTH = 253;
const DEFAULT_DROPDOWN_MAX_HEIGHT = 270;
const TABS = [
    {
        id: CatalogAttributeDataType.ATTRIBUTE,
        iconOnly: true,
        icon: "gd-icon-attribute",
    },
    {
        id: CatalogAttributeDataType.DATE_ATTRIBUTE,
        iconOnly: true,
        icon: "gd-icon-date",
    },
];
export function AttributeDropdownBody({ items, isLoading, closeDropdown, onSelect, }) {
    const { formatMessage } = useIntl();
    const [selectedTab, setSelectedTab] = useState(CatalogAttributeDataType.ATTRIBUTE);
    const [searchString, setSearchString] = useState("");
    const displayItems = searchAttributes(items, selectedTab, searchString);
    const handleTabSelect = (tab) => {
        setSelectedTab(tab.id);
    };
    const searchPlaceholderText = formatMessage(messages["hierarchyAttributeSearch"]);
    return (_jsx(DropdownList, { className: "attribute-hierarchy-attribute-dropdown-body s-attribute-hierarchy-attribute-dropdown-body", tabsClassName: "date-attribute-dropdown-tabs s-attribute-hierarchy-attribute-dropdown-tabs", width: DEFAULT_DROPDOWN_WIDTH, maxHeight: DEFAULT_DROPDOWN_MAX_HEIGHT, showSearch: true, searchPlaceholder: searchPlaceholderText, searchString: searchString, onSearch: setSearchString, items: displayItems, itemsCount: displayItems.length, showTabs: true, tabs: TABS, onTabSelect: handleTabSelect, selectedTabId: selectedTab, isLoading: isLoading, renderItem: ({ item }) => {
            const handleClick = () => {
                closeDropdown();
                onSelect(item);
            };
            return (_jsx(SingleSelectListItem, { className: "attribute-hierarchy-attribute-dropdown-item s-attribute-hierarchy-attribute-dropdown-item", title: item.title, onClick: handleClick, icon: item.icon }));
        } }));
}
//# sourceMappingURL=AttributeDropdownBody.js.map