import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import styled from "styled-components";
import { DataUtilities } from "../../../../Common/DataUtilities";
import { DeleteGrayIcon } from "../../../../CommonUI/Icon/DeleteGrayIcon";
import { ObserveState } from "../../../../CommonUI/StateManagement/ObserveState";
import { StateManager } from "../../../../CommonUI/StateManagement/StateManager";
import { ActionWrapper, EditColumnWrapper, EditColumnAction, StyledDataTypeRender } from "../../CommonStyles";
import { Error } from "../../CommonUI/Error";
import { DataTypePicker } from "../../../../CommonUI/DataTypePicker";
export const ValueTableResultColumnHeader = (props) => {
    const { resultColumn, ruleDefinition } = props;
    const onRemove = (event) => {
        event.stopPropagation();
        ruleDefinition.removeResultColumn(resultColumn._id);
        StateManager.propertyChanged(ruleDefinition, "resultColumns");
    };
    return (_jsx(RuleTableHeaderDiv, { children: _jsx(ObserveState, { listenTo: resultColumn, properties: ["name", "dataType"], control: () => {
                var _a;
                let validationIssues = ruleDefinition.getResultColumnValidationIssues(resultColumn);
                return (_jsxs(RuleTableHeaderVariable, { children: [(_a = resultColumn.name) !== null && _a !== void 0 ? _a : "Variable", _jsx(Error, { issues: validationIssues }, void 0),
                        _jsx(EditColumnWrapper, Object.assign({ className: "edit-wrapper" }, { children: ruleDefinition.canChangeOutputs && ruleDefinition.resultColumns.length > 1 ? (_jsx(EditColumnAction, Object.assign({ onClick: onRemove }, { children: _jsx(DeleteGrayIcon, {}, void 0) }), void 0)) : null }), void 0),
                        _jsx(ActionWrapper, { children: _jsx(StyledDataTypeRender, { children: _jsx(DataTypePicker, { dataDef: ruleDefinition.getResultColumnType(resultColumn) ||
                                        DataUtilities.createDataByType(resultColumn.dataType, resultColumn.name), updateCallback: (type) => {
                                        ruleDefinition.setResultColumnType(resultColumn, type);
                                        StateManager.propertyChanged(resultColumn, "dataType");
                                    }, readonly: !ruleDefinition.canChangeOutputs }, void 0) }, void 0) }, void 0)] }, void 0));
            } }, void 0) }, void 0));
};
const RuleTableHeaderDiv = styled.div `
    display: flex;
    flex-direction: row;
`;
const RuleTableHeaderVariable = styled.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-family: Inter;
    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=ValueTableResultColumnHeader.js.map