import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
// (C) 2025-2026 GoodData Corporation
import { useCallback, useId } from "react";
import cx from "classnames";
import { useIntl } from "react-intl";
import { dashboardAttributeFilterItemLocalIdentifier, } from "@gooddata/sdk-model";
import { AttributeFilterButton, } from "@gooddata/sdk-ui-filters";
import { UiChip, UiSkeleton, UiTooltip } from "@gooddata/sdk-ui-kit";
import { useDashboardSelector } from "../../../model/react/DashboardStoreProvider.js";
import { selectAvailableAttributeFilterSelectionTypes } from "../../../model/store/config/configSelectors.js";
import { StandaloneDashboardAttributeFilter } from "../../../presentation/filterBar/attributeFilter/DefaultDashboardAttributeFilter.js";
export function AttributeBar(props) {
    const intl = useIntl();
    const deleteAriaLabel = intl.formatMessage({ id: "kdaDialog.dialog.bars.attribute.deleteLabel" });
    const localIdentifier = dashboardAttributeFilterItemLocalIdentifier(props.attribute);
    const config = props.attributeConfigs.find((attribute) => attribute.localIdentifier === localIdentifier);
    const displayAsLabel = config?.displayAsLabel;
    return (_jsx("div", { className: cx("gd-kda-dialog-bar__attribute"), children: _jsx(KdaAttributeFilterWrapper, { filter: props.attribute, displayAsLabel: displayAsLabel, overlayPositionType: "absolute", deleteAriaLabel: deleteAriaLabel, onChange: props.onChange, onDelete: props.onDelete }) }));
}
function KdaAttributeFilterWrapper({ filter, displayAsLabel, overlayPositionType, deleteAriaLabel, onChange, onDelete, }) {
    const handleFilterChanged = useCallback((newFilter) => {
        onChange?.(newFilter);
    }, [onChange]);
    const handleFilterDeleted = useCallback((filter) => {
        onDelete?.(filter);
    }, [onDelete]);
    return (_jsx(StandaloneDashboardAttributeFilter, { filter: filter, displayAsLabel: displayAsLabel, overlayPositionType: overlayPositionType, onFilterChanged: handleFilterChanged, AttributeFilterComponent: (afProps) => (_jsx(KdaAttributeFilterComponent, { ...afProps, currentFilter: filter, onDelete: handleFilterDeleted, deleteAriaLabel: deleteAriaLabel ?? "" })), AttributeFilterLoadingComponent: KdaAttributeFilterLoadingComponent }));
}
function KdaAttributeFilterComponent({ onDelete, currentFilter, deleteAriaLabel, ...props }) {
    const allAvailableSelectionTypes = useDashboardSelector(selectAvailableAttributeFilterSelectionTypes);
    return (_jsx(AttributeFilterButton, { ...props, menuConfig: { availableSelectionTypes: allAvailableSelectionTypes, showLabelsSwitch: false }, LoadingComponent: KdaAttributeFilterLoadingComponent, DropdownButtonComponent: (ddProps) => (_jsx(KdaAttributeFilterDropdownButtonComponent, { ...ddProps, deleteAriaLabel: deleteAriaLabel, currentFilter: currentFilter, onDelete: onDelete })) }));
}
function KdaAttributeFilterLoadingComponent() {
    return _jsx(UiSkeleton, { itemWidth: 160, itemHeight: 27, itemBorderRadius: 20 });
}
function KdaAttributeFilterDropdownButtonComponent(props) {
    const label = `${props.title}: ${props.subtitle}`;
    const tag = props.selectedItemsCount ? `(${props.selectedItemsCount})` : undefined;
    const attributeFilterTooltipId = useId();
    const tooltipContent = (_jsxs(_Fragment, { children: [label, tag ? ` ${tag}` : null] }));
    return (_jsx(UiTooltip, { id: attributeFilterTooltipId, arrowPlacement: "top-start", content: tooltipContent, optimalPlacement: true, triggerBy: ["hover", "focus"], anchor: _jsx(UiChip, { label: label, isDeletable: true, tag: tag, isLocked: false, isActive: props.isOpen ?? false, onClick: props.onClick, onDelete: () => {
                props.onDelete?.(props.currentFilter);
            }, onDeleteKeyDown: (event) => {
                // Do not propagate event to parent as attribute filter would always open
                event.stopPropagation();
            }, accessibilityConfig: {
                isExpanded: props.isOpen ?? false,
                popupId: props.dropdownId,
                popupType: "dialog",
                deleteAriaLabel: props.deleteAriaLabel,
                ariaDescribedBy: attributeFilterTooltipId,
            }, buttonRef: props.buttonRef }) }));
}
//# sourceMappingURL=AttributeBar.js.map