import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
// (C) 2022-2026 GoodData Corporation
import { areObjRefsEqual } from "@gooddata/sdk-model";
import { Bubble, BubbleHoverTrigger } from "@gooddata/sdk-ui-kit";
import { useDashboardSelector } from "../../../../../../model/react/DashboardStoreProvider.js";
import { selectSupportsSettingConnectingAttributes } from "../../../../../../model/store/backendCapabilities/backendCapabilitiesSelectors.js";
import { ParentFiltersListItem } from "./ParentFiltersListItem.js";
import { ParentFiltersListItemWithoutConnectingAttributes } from "./ParentFiltersListItemWithoutConnectingAttributes.js";
const ARROW_OFFSETS = { "cr cl": [20, 0], "cl cr": [-10, 0] };
const ALIGN_POINTS = [{ align: "cr cl" }, { align: "cl cr" }];
export function ParentFiltersList({ parents, currentFilterLocalId, setParents, onConnectingAttributeChanged, connectingAttributes, attributes, disabled, disabledTooltip, validParents, }) {
    const supportsSettingConnectingAttributes = useDashboardSelector(selectSupportsSettingConnectingAttributes);
    if (parents.length < 1) {
        return null;
    }
    return (_jsxs(BubbleHoverTrigger, { showDelay: 0, hideDelay: 0, children: [
            _jsx("div", { className: "gd-infinite-list", children: parents.map((item, index) => {
                    if (supportsSettingConnectingAttributes) {
                        return (_jsx(ParentFiltersListItem, { currentFilterLocalId: currentFilterLocalId, item: item, disabled: disabled, onClick: setParents, onConnectingAttributeSelect: onConnectingAttributeChanged, connectingAttributes: connectingAttributes[index], title: item.title ?? attributes[index].title }, item.localIdentifier));
                    }
                    else {
                        /**
                         * When connecting attributes are not used, we want to validate parent against the list of valid parents.
                         */
                        const isParentValid = validParents.some((validParent) => areObjRefsEqual(validParent, item.displayForm));
                        return (_jsx(ParentFiltersListItemWithoutConnectingAttributes, { currentFilterLocalId: currentFilterLocalId, item: item, disabled: disabled, onClick: setParents, title: item.title ?? attributes[index].title, isValid: isParentValid }, item.localIdentifier));
                    }
                }) }), Boolean(disabled) && (_jsx(Bubble, { arrowOffsets: ARROW_OFFSETS, alignPoints: ALIGN_POINTS, children: _jsx("div", { children: disabledTooltip }) }))] }));
}
//# sourceMappingURL=ParentFiltersList.js.map