import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
import React from "react";
import { PlusGrayIcon } from "../../../../CommonUI/Icon/PlusGrayIcon";
import { StateManager } from "../../../../CommonUI/StateManagement/StateManager";
import { TestContext } from "../../../../Tester/TestContext";
import { RuleTableIndexColumn, RuleTableHeaderActionColumn, RuleTableHeaderSplit, } from "../../../DesignUI/CommonStyles";
import { XResultColumn } from "../../CommonUI/XResultColumn";
import { RuleTableHeaderColumn } from "./RuleTableHeaderColumn";
export const RuleTableHeader = (props) => {
    const { ruleDefinition, editContext } = props;
    const testContext = React.useContext(TestContext);
    const onAddNewColumnHeader = () => {
        if (testContext)
            return;
        ruleDefinition.addRuleColumn();
        StateManager.propertyChanged(ruleDefinition, "ruleColumns");
    };
    const onAddNewResultColumnHeader = () => {
        if (testContext)
            return;
        ruleDefinition.addResultColumn();
        StateManager.propertyChanged(ruleDefinition, "resultColumns");
    };
    return (_jsxs(_Fragment, { children: [_jsx(RuleTableIndexColumn, {}, void 0),
            ruleDefinition.ruleColumns.map((rule, idx) => {
                return (_jsx(RuleTableHeaderColumn, { rule: rule, ruleDefinition: ruleDefinition, editContext: editContext }, idx));
            }),
            _jsx(RuleTableHeaderActionColumn, Object.assign({ onClick: onAddNewColumnHeader, "data-testid": "btn-rule-table-add-new-column" }, { children: !testContext && _jsx(PlusGrayIcon, {}, void 0) }), void 0),
            ruleDefinition.resultColumns.map((rescol) => (_jsx(XResultColumn, { resultColumn: rescol, ruleDefinition: ruleDefinition }, rescol._id))),
            _jsx(RuleTableHeaderActionColumn, Object.assign({ onClick: onAddNewResultColumnHeader, "data-testid": "btn-rule-table-add-new-result-column" }, { children: ruleDefinition.canChangeOutputs && !testContext ? _jsx(PlusGrayIcon, {}, void 0) : null }), void 0),
            _jsx(RuleTableHeaderSplit, { width: 24 }, void 0),
            _jsx(RuleTableIndexColumn, { height: 1 }, void 0),
            ruleDefinition.ruleColumns.map((_, idx) => {
                return _jsx(RuleTableHeaderSplit, {}, idx);
            }),
            _jsx(RuleTableHeaderSplit, { width: 24 }, void 0),
            ruleDefinition.resultColumns.map((rescol) => (_jsx(RuleTableHeaderSplit, {}, rescol._id))),
            _jsx(RuleTableHeaderSplit, { width: 24 }, void 0),
            _jsx(RuleTableHeaderSplit, { width: 24 }, void 0)] }, void 0));
};
//# sourceMappingURL=RuleTableHeader.js.map