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 { EditButton } from "../../../DesignUI/EditButton";
import { ActionWrapper, EditColumnAction, EditColumnWrapper } from "../../CommonStyles";
import { Error } from "../../CommonUI/Error";
import { StateManager } from "../../../../CommonUI/StateManagement/StateManager";
import { DeleteGrayIcon } from "../../../../CommonUI/Icon/DeleteGrayIcon";
import { ColumnVariablePicker } from "../../CommonUI/ColumnVariablePicker";
import { TestContext } from "../../../../Tester/TestContext";
export const RuleTableHeaderColumn = (props) => {
    const { rule, editContext, ruleDefinition } = props;
    const dataDefinition = ruleDefinition.getInputDefinition();
    const testContext = React.useContext(TestContext);
    const onSelVariable = () => {
        editContext.selectedColumnHeader = rule;
    };
    const onRemoveColumn = (event) => {
        event.stopPropagation();
        ruleDefinition.removeRuleColumn(rule._id);
        StateManager.propertyChanged(ruleDefinition, "ruleColumns");
    };
    return (_jsx(RuleTableHeaderDiv, { children: _jsx(ObserveState, { listenTo: rule, properties: ["path"], control: () => {
                var _a, _b;
                let issues = ruleDefinition.getRuleColumnValidationIssues(rule);
                return (_jsxs(RuleTableHeaderVariable, Object.assign({ notSet: !rule.path, onClick: onSelVariable }, { children: [(_b = (_a = rule.name) !== null && _a !== void 0 ? _a : rule.path) !== null && _b !== void 0 ? _b : "Variable", !testContext && (_jsxs(_Fragment, { children: [_jsx(ActionWrapper, { children: _jsx(EditButton, { onClick: onSelVariable, className: "edit-button", dataTestId: `btn-open-select-variable` }, void 0) }, void 0),
                                _jsx(EditColumnWrapper, Object.assign({ className: "edit-wrapper" }, { children: ruleDefinition.canChangeInputs && ruleDefinition.ruleColumns.length > 1 && (_jsx(EditColumnAction, Object.assign({ onClick: onRemoveColumn }, { children: _jsx(DeleteGrayIcon, {}, void 0) }), void 0)) }), void 0),
                                _jsx(ColumnVariablePicker, { rule: rule, editContext: editContext, allowNew: ruleDefinition.canChangeInputs, dataDefinition: dataDefinition, onSet: (rule, path) => {
                                        ruleDefinition.setRuleColumn(rule, path);
                                        StateManager.propertyChanged(rule, "path");
                                        StateManager.changed(ruleDefinition);
                                    } }, void 0)] }, void 0)),
                        _jsx(Error, { issues: issues }, 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: 14px 16px 13px;

    color: ${(props) => (props.notSet ? "rgba(39, 41, 50, 0.3)" : "rgba(39, 41, 50)")};

    cursor: pointer;

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

        transition: opacity 0.2s ease-in;
    }

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