"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RuleTableHeader = void 0;
const tslib_1 = require("tslib");
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = tslib_1.__importDefault(require("react"));
const PlusGrayIcon_1 = require("../../../../CommonUI/Icon/PlusGrayIcon");
const StateManager_1 = require("@appglue/common/dist/Common/StateManager");
const TestContext_1 = require("../../../../CommonUI/Testing/TestContext");
const CommonStyles_1 = require("../../../DesignUI/CommonStyles");
const XResultColumn_1 = require("../../CommonUI/XResultColumn");
const RuleTableHeaderColumn_1 = require("./RuleTableHeaderColumn");
const RuleTableHeader = (props) => {
    const { ruleDefinition, editContext } = props;
    const testContext = react_1.default.useContext(TestContext_1.TestContext);
    const onAddNewColumnHeader = () => {
        if (testContext)
            return;
        ruleDefinition.addRuleColumn();
        StateManager_1.StateManager.propertyChanged(ruleDefinition, "ruleColumns");
    };
    const onAddNewResultColumnHeader = () => {
        if (testContext)
            return;
        ruleDefinition.addResultColumn();
        StateManager_1.StateManager.propertyChanged(ruleDefinition, "resultColumns");
    };
    return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(CommonStyles_1.RuleTableIndexColumn, {}), ruleDefinition.ruleColumns.map((rule, idx) => {
                return ((0, jsx_runtime_1.jsx)(RuleTableHeaderColumn_1.RuleTableHeaderColumn, { rule: rule, ruleDefinition: ruleDefinition, editContext: editContext }, idx));
            }), (0, jsx_runtime_1.jsx)(CommonStyles_1.RuleTableHeaderActionColumn, { onClick: onAddNewColumnHeader, "data-testid": "btn-rule-table-add-new-column", children: !testContext && (0, jsx_runtime_1.jsx)(PlusGrayIcon_1.PlusGrayIcon, {}) }), ruleDefinition.resultColumns.map((rescol) => ((0, jsx_runtime_1.jsx)(XResultColumn_1.XResultColumn, { resultColumn: rescol, ruleDefinition: ruleDefinition }, rescol._id))), (0, jsx_runtime_1.jsx)(CommonStyles_1.RuleTableHeaderActionColumn, { onClick: onAddNewResultColumnHeader, "data-testid": "btn-rule-table-add-new-result-column", children: ruleDefinition.canChangeOutputs && !testContext ? (0, jsx_runtime_1.jsx)(PlusGrayIcon_1.PlusGrayIcon, {}) : null }), (0, jsx_runtime_1.jsx)(CommonStyles_1.RuleTableHeaderSplit, { width: 24 }), (0, jsx_runtime_1.jsx)(CommonStyles_1.RuleTableIndexColumn, { height: 1 }), ruleDefinition.ruleColumns.map((_, idx) => {
                return (0, jsx_runtime_1.jsx)(CommonStyles_1.RuleTableHeaderSplit, {}, idx);
            }), (0, jsx_runtime_1.jsx)(CommonStyles_1.RuleTableHeaderSplit, { width: 24 }), ruleDefinition.resultColumns.map((rescol) => ((0, jsx_runtime_1.jsx)(CommonStyles_1.RuleTableHeaderSplit, {}, rescol._id))), (0, jsx_runtime_1.jsx)(CommonStyles_1.RuleTableHeaderSplit, { width: 24 }), (0, jsx_runtime_1.jsx)(CommonStyles_1.RuleTableHeaderSplit, { width: 24 })] }));
};
exports.RuleTableHeader = RuleTableHeader;
//# sourceMappingURL=RuleTableHeader.js.map