import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
import React from "react";
import styled from "styled-components";
import { ObserveState } from "../../../../CommonUI/StateManagement/ObserveState";
import { StateManager } from "../../../../CommonUI/StateManagement/StateManager";
import { XExpressionView } from "../../../../Expressions/XExpressionView";
import { EditColumnWrapper, EditColumnAction, ActionWrapper, StyledDataTypeRender } from "../../CommonStyles";
import { DeleteGrayIcon } from "../../../../CommonUI/Icon/DeleteGrayIcon";
import { Error } from "../../CommonUI/Error";
import { DataTypePicker } from "../../../../CommonUI/DataTypePicker";
import { TestContext } from "../../../../Tester/TestContext";
export const XValueTableRuleColumnHeader = (props) => {
    const { ruleColumn, editContext, ruleDefinition } = props;
    const testContext = React.useContext(TestContext);
    const onRemove = (event) => {
        event.stopPropagation();
        if (testContext)
            return;
        ruleDefinition.removeColumn(ruleColumn._id);
        StateManager.propertyChanged(ruleDefinition, "columns");
    };
    const onClickSetVariableDialog = (event) => {
        event.stopPropagation();
        editContext.selectedColForVariable = ruleColumn;
    };
    const onClickSetRuleDialog = (event) => {
        event.stopPropagation();
        editContext.selectedColForRule = ruleColumn;
    };
    return (_jsx(RuleTableHeaderDiv, { children: _jsx(ObserveState, { listenTo: ruleColumn, properties: ["columnName", "getRule", "cellData", "expression"], control: () => {
                let validationIssues = ruleColumn.getDesignValidationIssues();
                return (_jsx(_Fragment, { children: _jsxs(ValueTableRuleColumnRender, Object.assign({ onClick: onClickSetVariableDialog }, { children: [_jsx(ExpressionRender, Object.assign({ onClick: onClickSetRuleDialog }, { children: _jsx(TestContext.Provider, Object.assign({ value: undefined }, { children: _jsx(XExpressionView, { expression: ruleColumn.expression, color: {
                                            expression: "#4050A6",
                                            value: "#272932",
                                            variable: "#272932",
                                            missing: "rgba(39, 41, 50, 0.3)",
                                        }, hideValidation: true, onDone: () => {
                                            StateManager.propertyChanged(ruleColumn, "expression");
                                        } }, void 0) }), void 0) }), void 0),
                            _jsx(Error, { issues: validationIssues }, void 0),
                            _jsx(EditColumnWrapper, Object.assign({ className: "edit-wrapper" }, { children: ruleDefinition.columns.length > 1 && !testContext ? (_jsx(EditColumnAction, Object.assign({ onClick: onRemove }, { children: _jsx(DeleteGrayIcon, {}, void 0) }), void 0)) : null }), void 0),
                            _jsx(ActionWrapper, { children: testContext ? (_jsx(_Fragment, { children: ruleColumn.cellData.type }, void 0)) : (_jsx(StyledDataTypeRender, { children: _jsx(DataTypePicker, { dataDef: ruleColumn.cellData, updateCallback: (type) => {
                                            ruleDefinition.setRuleColumnType(ruleColumn, type);
                                            StateManager.propertyChanged(ruleColumn, "cellData");
                                        } }, void 0) }, void 0)) }, void 0)] }), void 0) }, void 0));
            } }, void 0) }, void 0));
};
const RuleTableHeaderDiv = styled.div `
    display: flex;
    flex-direction: row;
    position: relative;
`;
const ValueTableRuleColumnRender = 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;
    color: rgba(39, 41, 50);

    display: flex;
    flex-direction: column;
    justify-content: center;

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

    &:hover {
        .edit-button,
        .edit-wrapper {
            opacity: 1;
        }
    }
`;
const ExpressionRender = styled.div `
    color: #4050a6;
    cursor: pointer;

    padding-top: 15px;
`;
//# sourceMappingURL=ValueTableRuleColumnHeader.js.map