import { jsx as _jsx } from "react/jsx-runtime";
// (C) 2025-2026 GoodData Corporation
import { useCallback, useId, useMemo } from "react";
import { FormattedMessage, useIntl } from "react-intl";
import { Typography, UiIconButton, UiTooltip } from "@gooddata/sdk-ui-kit";
import { AttributesDropdown } from "../../presentation/filterBar/attributeFilter/addAttributeFilter/AttributesDropdown.js";
import { useKdaState } from "../providers/KdaState.js";
import { useAddNewAttributeHandler } from "./hooks/useAddNewAttributeHandler.js";
import { useUnusedAttributes } from "./hooks/useUnusedAttributes.js";
export function AddFilterButton() {
    const intl = useIntl();
    const attributes = useUnusedAttributes();
    const dateDatasets = useMemo(() => [], []);
    const { setState } = useKdaState();
    const tooltipText = intl.formatMessage({ id: "kdaDialog.dialog.filters.add.tooltip" });
    const searchAriaLabel = intl.formatMessage({ id: "kdaDialog.dialog.filters.search" });
    const ariaLabelledBy = useId();
    const attributesDropdownId = useId();
    const isAddButtonDisabled = attributes.length === 0;
    const { onSelectCallback } = useAddNewAttributeHandler();
    const DropdownButtonComponent = useCallback(({ id, buttonRef, isOpen, onClick }) => (_jsx(UiTooltip, { arrowPlacement: "left", triggerBy: ["hover", "focus"], content: tooltipText, anchor: _jsx(UiIconButton, { id: id, icon: "plus", label: tooltipText, onClick: onClick, size: "small", variant: "tertiary", isDisabled: isAddButtonDisabled, ref: buttonRef, accessibilityConfig: {
                ariaLabel: tooltipText,
                ariaControls: isOpen ? attributesDropdownId : undefined,
                ariaExpanded: isOpen,
                ariaHaspopup: "dialog",
            } }) })), [attributesDropdownId, isAddButtonDisabled, tooltipText]);
    return (_jsx(AttributesDropdown, { id: attributesDropdownId, openOnInit: false, dateDatasets: dateDatasets, attributes: attributes, onSelect: onSelectCallback, onOpen: () => {
            setState({
                addFilterDropdownOpen: true,
            });
        }, onClose: () => {
            setState({
                addFilterDropdownOpen: false,
            });
        }, accessibilityConfig: {
            ariaLabelledBy,
            searchAriaLabel,
        }, overlayPositionType: "sameAsTarget", className: "gd-kda-attribute-add-dropdown", DropdownButtonComponent: DropdownButtonComponent, DropdownTitleComponent: () => (_jsx("div", { className: "gd-automation-filters__dropdown-header", children: _jsx(Typography, { tagName: "h3", id: ariaLabelledBy, children: _jsx(FormattedMessage, { id: "kdaDialog.dialog.filters.title" }) }) })), renderNoData: () => (_jsx("div", { className: "gd-automation-filters__dropdown-no-filters", children: _jsx(FormattedMessage, { id: "kdaDialog.dialog.filters.noFilters" }) })) }));
}
//# sourceMappingURL=AddFilterButton.js.map