"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
var react_1 = __importStar(require("react"));
var mdm_sdk_1 = require("@reltio/mdm-sdk");
var FilterValueEditor_1 = require("../FilterValueEditor");
var styles_1 = require("./styles");
var AttributesValuesEditor = function (_a) {
    var rowData = _a.rowData, rowContext = _a.rowContext;
    var styles = (0, styles_1.useStyles)();
    var canFilterAcceptValues = (rowData === null || rowData === void 0 ? void 0 : rowData.attribute) && (0, mdm_sdk_1.checkIfOptionHasValues)(rowData.filter);
    var changeFilter = rowContext.changeFilter;
    var _b = (rowData || {}), _c = _b.values, values = _c === void 0 ? [] : _c, _d = _b.attribute, _e = _d === void 0 ? {} : _d, attrType = _e.attrType, _f = _e.fieldName, fieldName = _f === void 0 ? null : _f, filter = _b.filter, id = _b.id, operator = _b.operator;
    var valueDataTypeDefinition = attrType && (0, mdm_sdk_1.getAttrDataTypeDefinition)(attrType);
    var filterValueDataTypeDefinition = valueDataTypeDefinition && (0, mdm_sdk_1.getDataTypeDefinitionForFilterValue)(valueDataTypeDefinition, filter);
    var editorFilter = (0, react_1.useMemo)(function () { return ({
        filter: filter,
        fieldName: fieldName,
        operator: operator,
        values: values || []
    }); }, [filter, fieldName, operator, values]);
    var TextFieldProps = (0, react_1.useMemo)(function () { return ({
        InputProps: {
            classes: {
                root: styles.input
            }
        }
    }); }, [styles]);
    var editorClasses = (0, react_1.useMemo)(function () { return ({ root: styles.root }); }, [styles]);
    var changeValue = (0, react_1.useCallback)(function (newValues) {
        var newFilter = {
            fieldName: fieldName,
            filter: filter,
            operator: operator,
            values: newValues
        };
        changeFilter(newFilter, id);
    }, [fieldName, filter, operator, changeFilter, id]);
    return (react_1.default.createElement("div", { className: styles.valuesEditor }, (rowData === null || rowData === void 0 ? void 0 : rowData.attribute) && canFilterAcceptValues && (react_1.default.createElement(FilterValueEditor_1.FilterValueEditor, { "data-reltio-id": "filter-value-editor", filter: editorFilter, onChange: changeValue, dataTypeDefinition: filterValueDataTypeDefinition, fullWidth: true, TextFieldProps: TextFieldProps, color: "primary", classes: editorClasses, orientation: "horizontal" }))));
};
exports.default = (0, react_1.memo)(AttributesValuesEditor);
