var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
import React from 'react';
import classnames from 'classnames';
import { __, assoc, pipe } from 'ramda';
import { checkIfOptionHasValues } from '@reltio/mdm-sdk';
import { COMMON_TEXT_FIELD_PROPS } from '../constants';
import { DropDownEditor } from '../DropDownEditor';
import { FilterValueEditor } from '../FilterValueEditor';
import { useStyles } from './styles';
export var FilterEditor = function (_a) {
    var value = _a.value, onChange = _a.onChange, filterOptions = _a.filterOptions, dataTypeDefinition = _a.dataTypeDefinition, classes = _a.classes, ValueEditorProps = _a.ValueEditorProps;
    var styles = useStyles();
    var firstOption = filterOptions[0];
    var filterOption = value.filter || firstOption.value;
    var filter = __assign(__assign({}, value), { filter: filterOption });
    var canFilterAcceptValues = checkIfOptionHasValues(filterOption);
    return (React.createElement(React.Fragment, null,
        React.createElement(DropDownEditor, { TextFieldProps: COMMON_TEXT_FIELD_PROPS, className: classnames(classes.option, styles.dropDownEditor), value: filterOption, entries: filterOptions, onChange: pipe(assoc('filter', __, filter), assoc('values', []), onChange), classes: { root: classnames(styles.root, styles.selectorRoot), icon: styles.icon } }),
        canFilterAcceptValues && (React.createElement(FilterValueEditor, __assign({ filter: filter, onChange: pipe(assoc('values', __, filter), onChange), dataTypeDefinition: dataTypeDefinition }, ValueEditorProps)))));
};
