import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
// (C) 2020-2026 GoodData Corporation
import { Checkbox, DialogListHeader, UiTooltip } from "@gooddata/sdk-ui-kit";
import { isDrillFiltersConfigOptionSelected } from "./types.js";
export function DrillFiltersConfigSection({ title, dataTestId, options, selectedIds, onSelectionChange, }) {
    if (options.length === 0) {
        return null;
    }
    const getNextSelectedIds = (id, checked) => checked
        ? selectedIds.includes(id)
            ? selectedIds
            : [...selectedIds, id]
        : selectedIds.filter((selectedId) => selectedId !== id);
    const handleOptionChange = (id) => (checked) => onSelectionChange(getNextSelectedIds(id, checked));
    return (_jsxs("div", { className: "gd-drill-filters-config-section", "data-testid": dataTestId, children: [
            _jsx(DialogListHeader, { title: title, className: "gd-drill-filters-config-section-header" }), _jsx("div", { className: "gd-drill-filters-config-section-items", children: options.map((option) => {
                    const isChecked = isDrillFiltersConfigOptionSelected(option, selectedIds);
                    const isDisabled = !!option.disabled;
                    const checkbox = (_jsx(Checkbox, { value: isChecked, onChange: handleOptionChange(option.id), text: option.title, labelSize: "small", disabled: isDisabled }));
                    return (_jsx("div", { className: "gd-drill-filters-config-section-item", title: isDisabled ? undefined : option.title, children: option.disabled ? (_jsx(UiTooltip, { triggerBy: ["hover", "focus"], arrowPlacement: "left", optimalPlacement: true, content: _jsx("div", { className: "gd-drill-filters-config-section-tooltip", children: option.disabled.message }), anchor: checkbox, anchorWrapperStyles: { lineHeight: 0, width: "fit-content" } })) : (checkbox) }, option.id));
                }) })
        ] }));
}
//# sourceMappingURL=DrillFiltersConfigSection.js.map