"use strict";
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);
};
var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.FilterValueEditor = void 0;
var react_1 = __importDefault(require("react"));
var ui_i18n_1 = __importDefault(require("ui-i18n"));
var mdm_sdk_1 = require("@reltio/mdm-sdk");
var ramda_1 = require("ramda");
var DateRangeEditor_1 = require("../DateRangeEditor");
var DataTypeValueEditor_1 = require("../DataTypeValueEditor");
var RangeDataTypeValueEditor_1 = require("./components/RangeDataTypeValueEditor");
var helpers_1 = require("./helpers");
var FilterValueEditor = function (_a) {
    var _b = _a.filter, _c = _b.values, values = _c === void 0 ? [] : _c, fieldName = _b.fieldName, filter = _b.filter, onChange = _a.onChange, dataTypeDefinition = _a.dataTypeDefinition, orientation = _a.orientation, TextFieldProps = _a.TextFieldProps, otherProps = __rest(_a, ["filter", "onChange", "dataTypeDefinition", "orientation", "TextFieldProps"]);
    var dataType = dataTypeDefinition.type;
    var value = (0, mdm_sdk_1.mapFilterValue)((0, helpers_1.toEditorValue)(dataType))(values[0]);
    var handleChange = (0, ramda_1.pipe)((0, mdm_sdk_1.mapFilterValue)((0, helpers_1.fromEditorValue)(dataType)), mdm_sdk_1.wrapInArray, onChange);
    if ((0, mdm_sdk_1.isDateRangeFilterOption)(filter)) {
        return (react_1.default.createElement(DateRangeEditor_1.DateRangeEditor, __assign({}, otherProps, { values: value, onChange: handleChange, dataTypeDefinition: dataTypeDefinition, label: ui_i18n_1.default.text('Date Range') })));
    }
    else if ((0, mdm_sdk_1.isRangeFilterOption)(filter)) {
        return (react_1.default.createElement(RangeDataTypeValueEditor_1.RangeDataTypeValueEditor, __assign({}, otherProps, { value: value, onChange: handleChange, fieldName: fieldName, dataTypeDefinition: dataTypeDefinition, orientation: orientation, TextFieldProps: TextFieldProps })));
    }
    else {
        var multipleProp = (0, mdm_sdk_1.isMultiValueOption)(filter) ? { multiple: true } : {};
        return (react_1.default.createElement(DataTypeValueEditor_1.DataTypeValueEditor, __assign({}, otherProps, multipleProp, { fieldName: fieldName, value: value, onChange: handleChange, dataTypeDefinition: dataTypeDefinition, TextFieldProps: TextFieldProps })));
    }
};
exports.FilterValueEditor = FilterValueEditor;
