import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { PlusOutlined } from '@ant-design/icons';
import { Fragment } from 'react';
import { SectionRow, Select } from '../components';
import { useDeepMemo } from '../hooks';
import FilterInput from './FilterInput';
import MemberDropdown from './MemberDropdown';
import MissingMemberTooltip from './MissingMemberTooltip';
import RemoveButtonGroup from './RemoveButtonGroup';
const FilterGroup = ({ disabled = false, members, availableMembers, addMemberName, updateMethods, missingMembers, }) => {
    const operatorsByMemberName = useDeepMemo(() => {
        return members.reduce((memo, item) => ({
            ...memo,
            [item.member]: [...(memo[item.member] || []), item.operator],
        }), {});
    }, [members]);
    return (_jsxs(SectionRow, { children: [members.map((m) => {
                const isMissing = missingMembers.includes(m.member);
                const buttonGroup = (_jsx(RemoveButtonGroup, { disabled: disabled, className: disabled ? 'disabled' : null, color: isMissing ? 'danger' : 'primary', onRemoveClick: () => updateMethods.remove(m), children: _jsx(MemberDropdown, { disabled: disabled, availableCubes: availableMembers, style: {
                            minWidth: 150,
                        }, onClick: (updateWith) => updateMethods.update(m, { ...m, dimension: updateWith }), children: m.dimension.title }) }));
                return (_jsxs(Fragment, { children: [isMissing ? (_jsx(MissingMemberTooltip, { children: buttonGroup })) : (buttonGroup), _jsx(Select, { disabled: disabled, value: m.operator, style: { width: 200 }, onChange: (operator) => updateMethods.update(m, { ...m, operator }), children: m.operators.map((operator) => {
                                const isOperatorDisabled = operatorsByMemberName[m.member]?.includes(operator.name);
                                return (_jsx(Select.Option, { value: operator.name, title: isOperatorDisabled
                                        ? `There is already a filter applied with this operator for ${m.dimension?.title || m.name}`
                                        : operator.name, disabled: isOperatorDisabled, children: operator.title }, operator.name));
                            }) }), !['set', 'notSet'].includes(m.operator) ? (_jsx(FilterInput, { disabled: disabled, member: m, updateMethods: updateMethods }, "filterInput")) : null] }, `${m.member}-${m.operator}`));
            }), _jsx(MemberDropdown, { availableCubes: availableMembers, type: "dashed", disabled: disabled || members.find((m) => !m.operator), icon: _jsx(PlusOutlined, {}), onClick: (m) => updateMethods.add({ member: m }), children: !members.length ? addMemberName : null })] }));
};
export default FilterGroup;
//# sourceMappingURL=FilterGroup.js.map