"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RuleTableHeaderColumn = 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 ObserveState_1 = require("../../../../CommonUI/StateManagement/ObserveState");
const EditButton_1 = require("../../../DesignUI/EditButton");
const CommonStyles_1 = require("../../CommonStyles");
const Error_1 = require("../../CommonUI/Error");
const StateManager_1 = require("@appglue/common/dist/Common/StateManager");
const DeleteGrayIcon_1 = require("../../../../CommonUI/Icon/DeleteGrayIcon");
const ColumnVariablePicker_1 = require("../../CommonUI/ColumnVariablePicker");
const TestContext_1 = require("../../../../CommonUI/Testing/TestContext");
const RuleTableHeaderColumn = (props) => {
    const { rule, editContext, ruleDefinition } = props;
    const dataDefinition = ruleDefinition.getInputDefinition();
    const testContext = react_1.default.useContext(TestContext_1.TestContext);
    const onSelVariable = () => {
        editContext.selectedColumnHeader = rule;
    };
    const onRemoveColumn = (event) => {
        event.stopPropagation();
        editContext.removeRuleColumn(rule);
    };
    return ((0, jsx_runtime_1.jsx)(RuleTableHeaderDiv, { children: (0, jsx_runtime_1.jsx)(ObserveState_1.ObserveState, { listenTo: rule, properties: ["path"], control: () => {
                let issues = ruleDefinition.getRuleColumnValidationIssues(rule);
                return ((0, jsx_runtime_1.jsxs)(RuleTableHeaderVariable, { notSet: !rule.path, onClick: onSelVariable, children: [rule.name ?? rule.path ?? "Variable", !testContext && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(CommonStyles_1.ActionWrapper, { children: (0, jsx_runtime_1.jsx)(EditButton_1.EditButton, { onClick: onSelVariable, className: "edit-button", dataTestId: `btn-open-select-variable` }) }), (0, jsx_runtime_1.jsx)(CommonStyles_1.EditColumnWrapper, { className: "edit-wrapper", children: ruleDefinition.canChangeInputs && ruleDefinition.ruleColumns.length > 1 && ((0, jsx_runtime_1.jsx)(CommonStyles_1.EditColumnAction, { onClick: onRemoveColumn, children: (0, jsx_runtime_1.jsx)(DeleteGrayIcon_1.DeleteGrayIcon, {}) })) }), (0, jsx_runtime_1.jsx)(ColumnVariablePicker_1.ColumnVariablePicker, { rule: rule, editContext: editContext, allowNew: ruleDefinition.canChangeInputs, dataDefinition: dataDefinition, onSet: (rule, path) => {
                                        ruleDefinition.setRuleColumn(rule, path);
                                        StateManager_1.StateManager.propertyChanged(rule, "path");
                                        StateManager_1.StateManager.changed(ruleDefinition);
                                    } })] })), (0, jsx_runtime_1.jsx)(Error_1.Error, { issues: issues })] }));
            } }) }));
};
exports.RuleTableHeaderColumn = RuleTableHeaderColumn;
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: 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