"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.XResultColumn = void 0;
const tslib_1 = require("tslib");
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = tslib_1.__importDefault(require("react"));
const styled_components_1 = tslib_1.__importDefault(require("styled-components"));
const DataUtilities_1 = require("@appglue/common/dist/Common/DataUtilities");
const DataTypePicker_1 = require("../../../CommonUI/DataTypePicker");
const DeleteGrayIcon_1 = require("../../../CommonUI/Icon/DeleteGrayIcon");
const ObserveState_1 = require("../../../CommonUI/StateManagement/ObserveState");
const StateManager_1 = require("@appglue/common/dist/Common/StateManager");
const CommonStyles_1 = require("../CommonStyles");
const Error_1 = require("./Error");
const TestContext_1 = require("../../../CommonUI/Testing/TestContext");
const InlineTextEdit_1 = require("../../../CommonUI/InlineTextEdit");
const XResultColumn = (props) => {
    const { resultColumn, ruleDefinition } = props;
    const testContext = react_1.default.useContext(TestContext_1.TestContext);
    const onRemove = (event) => {
        event.stopPropagation();
        ruleDefinition.removeResultColumn(resultColumn._id);
        StateManager_1.StateManager.propertyChanged(ruleDefinition, "resultColumns");
    };
    return ((0, jsx_runtime_1.jsx)(RuleTableHeaderDiv, { children: (0, jsx_runtime_1.jsx)(ObserveState_1.ObserveState, { listenTo: resultColumn, properties: ["name", "dataType"], control: () => {
                let validationIssues = ruleDefinition.getResultColumnValidationIssues(resultColumn);
                return ((0, jsx_runtime_1.jsxs)(RuleTableHeaderVariable, { children: [(0, jsx_runtime_1.jsx)(InlineTextEdit_1.InlineTextEdit, { small: true, onEdit: (newValue) => {
                                ruleDefinition.getResultColumnType(resultColumn).name = newValue;
                                resultColumn.name = newValue;
                                //   ruleDefinition.setResultColumnType(resultColumn.)
                            }, text: resultColumn.name ?? "Variable" }), (0, jsx_runtime_1.jsx)(Error_1.Error, { issues: validationIssues }), (0, jsx_runtime_1.jsx)(CommonStyles_1.EditColumnWrapper, { className: "edit-wrapper", children: ruleDefinition.canChangeOutputs && ruleDefinition.resultColumns.length > 1 ? ((0, jsx_runtime_1.jsx)(CommonStyles_1.EditColumnAction, { onClick: onRemove, children: (0, jsx_runtime_1.jsx)(DeleteGrayIcon_1.DeleteGrayIcon, {}) })) : null }), (0, jsx_runtime_1.jsx)(CommonStyles_1.ActionWrapper, { children: testContext ? ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: resultColumn.dataType })) : ((0, jsx_runtime_1.jsx)(CommonStyles_1.StyledDataTypeRender, { children: (0, jsx_runtime_1.jsx)(DataTypePicker_1.DataTypePicker, { dataDef: ruleDefinition.getResultColumnType(resultColumn) ||
                                        DataUtilities_1.DataUtilities.createDataByType(resultColumn.dataType, resultColumn.name), updateCallback: (type) => {
                                        ruleDefinition.setResultColumnType(resultColumn, type);
                                        StateManager_1.StateManager.propertyChanged(resultColumn, "dataType");
                                    }, readonly: !ruleDefinition.canChangeOutputs }) })) })] }));
            } }) }));
};
exports.XResultColumn = XResultColumn;
const RuleTableHeaderDiv = styled_components_1.default.div `
    display: flex;
    flex-direction: row;
`;
const RuleTableHeaderVariable = styled_components_1.default.div `
    position: relative;

    min-width: 120px;
    min-height: 44px;

    width: 100%;
    height: 100%;

    background: #ffffff;
    border: 1px solid #4050a6;
    box-sizing: border-box;
    border-radius: 2px;

    font-size: 12px;
    font-style: normal;
    font-weight: 400;
    line-height: 17px;
    letter-spacing: 0px;
    text-align: left;
    padding: 29px 16px 13px;

    cursor: pointer;

    color: rgba(39, 41, 50);

    .edit-button,
    .edit-wrapper {
        opacity: 0;
    }

    &:hover {
        .edit-button,
        .edit-wrapper {
            opacity: 1;
        }
    }
`;
//# sourceMappingURL=XResultColumn.js.map