import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { FormattedMessage, useIntl } from "react-intl";
import { isIdentifierRef, isObjRef } from "@gooddata/sdk-model";
import { IconAttribute, IconAttributeFilter, IconFact, IconMetric, } from "@gooddata/sdk-ui-kit";
import { messages } from "../../../../../../../locales.js";
export function UnknownItemTitle() {
    return (_jsx("em", { children: _jsx(FormattedMessage, { id: "attributesDropdown.valuesLimiting.unknownItem" }) }));
}
function ItemTitleWithIcon({ title, tooltip, IconComponent, iconSize }) {
    return (_jsxs("span", { className: "attribute-filter__limit__item__title", title: tooltip, children: [IconComponent ? (_jsx(IconComponent, { className: "attribute-filter__limit__item__icon", width: iconSize, height: iconSize })) : null, _jsx("span", { className: "attribute-filter__limit__item__name", children: title ?? _jsx(UnknownItemTitle, {}) })
        ] }));
}
function AggregatedItemTitle({ titleNode, tooltip }) {
    return (_jsx("span", { className: "attribute-filter__limit__item__title--aggregated", title: tooltip, children: titleNode }));
}
const isMetric = (item) => isIdentifierRef(item) && item.type === "measure";
const isFact = (item) => isIdentifierRef(item) && item.type === "fact";
const isAttribute = (item) => isIdentifierRef(item) && item.type === "attribute";
const isParentFilter = (item) => !isObjRef(item);
export function LimitingItemTitle({ item, title }) {
    const intl = useIntl();
    const titleTooltip = title ?? intl.formatMessage(messages.filterUnknownItemTitle);
    if (isParentFilter(item)) {
        return (_jsx(ItemTitleWithIcon, { title: title, tooltip: titleTooltip, IconComponent: IconAttributeFilter, iconSize: 14 }));
    }
    if (isMetric(item)) {
        return (_jsx(ItemTitleWithIcon, { title: title, tooltip: titleTooltip, IconComponent: IconMetric, iconSize: 14 }));
    }
    if (isFact(item)) {
        return (_jsx(AggregatedItemTitle, { tooltip: intl.formatMessage(messages.filterSumMetricTitle, { fact: titleTooltip }), titleNode: _jsx(FormattedMessage, { id: "attributesDropdown.valuesLimiting.sumFact", values: {
                    fact: _jsx(ItemTitleWithIcon, { title: title, IconComponent: IconFact, iconSize: 18 }),
                } }) }));
    }
    if (isAttribute(item)) {
        return (_jsx(AggregatedItemTitle, { tooltip: intl.formatMessage(messages.filterCountMetricTitle, { attribute: titleTooltip }), titleNode: _jsx(FormattedMessage, { id: "attributesDropdown.valuesLimiting.countAttribute", values: {
                    attribute: (_jsx(ItemTitleWithIcon, { title: title, IconComponent: IconAttribute, iconSize: 18 })),
                } }) }));
    }
    return _jsx(ItemTitleWithIcon, { title: title, tooltip: titleTooltip });
}
export function LimitingItem(props) {
    return (_jsxs("div", { className: "attribute-filter__limit__item", children: [
            _jsx(LimitingItemTitle, { ...props }), _jsx("span", { className: "attribute-filter__limit__item__delete gd-icon-trash s-filter-limit-delete", onClick: props.onDelete, "aria-label": "Attribute filter limit delete" })
        ] }));
}
//# sourceMappingURL=LimitingItem.js.map