import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
// (C) 2007-2026 GoodData Corporation
import { useMemo } from "react";
import { useIntl } from "react-intl";
import { UiTooltip } from "../../@ui/UiTooltip/UiTooltip.js";
/**
 * @internal
 */
export function useInvertableSelectionStatusText(selectedItems, isInverted, getItemTitle) {
    const intl = useIntl();
    const isSelectionEmpty = selectedItems.length === 0;
    const isAll = isSelectionEmpty && isInverted;
    const isNone = isSelectionEmpty && !isInverted;
    const isAllExcept = !isSelectionEmpty && isInverted;
    const selectionString = useMemo(() => {
        return selectedItems.map((selectedItem) => getItemTitle(selectedItem)).join(", ");
    }, [selectedItems, getItemTitle]);
    const stringChunks = [];
    if (isAll) {
        stringChunks.push(intl.formatMessage({ id: "gs.list.all" }));
    }
    if (isNone) {
        stringChunks.push(intl.formatMessage({ id: "gs.filterLabel.none" }));
    }
    if (isAllExcept) {
        stringChunks.push(intl.formatMessage({ id: "gs.list.isNot" }));
    }
    let count = undefined;
    const selectedChunks = stringChunks.slice();
    if (!isAll && !isSelectionEmpty) {
        stringChunks.push(selectionString, `(${selectedItems.length})`);
        selectedChunks.push(selectionString);
        count = selectedItems.length;
    }
    return {
        count,
        text: selectedChunks.join(" "),
        whole: stringChunks.join(" "),
    };
}
/**
 * @internal
 */
export function InvertableSelectStatus({ selectedItems, getItemTitle, isInverted, }) {
    const intl = useIntl();
    const isSelectionEmpty = selectedItems.length === 0;
    const isAll = isSelectionEmpty && isInverted;
    const isNone = isSelectionEmpty && !isInverted;
    const isAllExcept = !isSelectionEmpty && isInverted;
    const selectionString = useMemo(() => {
        return selectedItems.map((selectedItem) => getItemTitle(selectedItem)).join(", ");
    }, [selectedItems, getItemTitle]);
    return (_jsxs(_Fragment, { children: [isAllExcept ? (_jsxs("span", { children: ["\u00A0", intl.formatMessage({ id: "gs.list.isNot" }), "\u00A0"] })) : (_jsxs("span", { children: ["\u00A0", intl.formatMessage({ id: "gs.list.is" }), "\u00A0"] })), isAll ? _jsx("b", { children: intl.formatMessage({ id: "gs.list.all" }) }) : null, isNone ? _jsx("b", { children: intl.formatMessage({ id: "gs.filterLabel.none" }) }) : null, !isAll && !isSelectionEmpty ? (_jsx(UiTooltip, { arrowPlacement: "top-start", triggerBy: ["hover"], content: selectionString, anchor: _jsxs(_Fragment, { children: [
                        _jsx("span", { className: "gd-shortened-text gd-selection-list s-dropdown-attribute-selection-list", children: selectionString }), `\xa0(${selectedItems.length})`] }) })) : null] }));
}
