"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 });
var react_1 = require("react");
var prop_types_1 = __importDefault(require("prop-types"));
var ramda_1 = require("ramda");
var mdm_sdk_1 = require("@reltio/mdm-sdk");
var constants_1 = require("../constants");
var EditorsFactory_1 = require("../EditorsFactory");
var useEditorContext_1 = require("./useEditorContext");
var styles_1 = require("./styles");
var DataTypeValueEditor = function (_a) {
    var fieldName = _a.fieldName, value = _a.value, onChange = _a.onChange, dataTypeDefinition = _a.dataTypeDefinition, _b = _a.TextFieldProps, TextFieldProps = _b === void 0 ? {} : _b, otherProps = __rest(_a, ["fieldName", "value", "onChange", "dataTypeDefinition", "TextFieldProps"]);
    var styles = (0, styles_1.useStyles)();
    var editorContext = (0, useEditorContext_1.useEditorContext)(fieldName, dataTypeDefinition);
    var isEmpty = function (value) {
        return (0, ramda_1.is)(Object, value) && (0, ramda_1.has)('value', value) ? (0, mdm_sdk_1.isEmptyValue)(value.value) : (0, mdm_sdk_1.isEmptyValue)(value);
    };
    TextFieldProps = (0, ramda_1.mergeDeepLeft)(TextFieldProps, __assign(__assign({}, constants_1.COMMON_TEXT_FIELD_PROPS), { className: styles.marginDense, InputProps: __assign(__assign({}, constants_1.COMMON_TEXT_FIELD_PROPS.InputProps), { disableUnderline: isEmpty(value) }) }));
    return EditorsFactory_1.EditorsFactory.build(dataTypeDefinition.type, __assign(__assign({ onChange: onChange, value: value, TextFieldProps: TextFieldProps }, editorContext), otherProps));
};
DataTypeValueEditor.propTypes = {
    fieldName: prop_types_1.default.string,
    value: prop_types_1.default.any,
    onChange: prop_types_1.default.func,
    dataTypeDefinition: prop_types_1.default.object
};
DataTypeValueEditor.displayName = 'DataTypeValueEditor';
exports.default = (0, react_1.memo)(DataTypeValueEditor);
