import { createElement as _createElement } from "react";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import React from "react";
import { ApplyIcon } from "../../../../CommonUI/Icon/ApplyIcon";
import { CloseRedIcon } from "../../../../CommonUI/Icon/CloseRedIcon";
import { DeleteGrayIcon } from "../../../../CommonUI/Icon/DeleteGrayIcon";
import { ObserveState } from "../../../../CommonUI/StateManagement/ObserveState";
import { StateManager } from "../../../../CommonUI/StateManagement/StateManager";
import { TestContext } from "../../../../Tester/TestContext";
import { RuleTableIndexColumn, RuleTableEmptyAddColumn, RuleTableHeaderActionColumn, } from "../../../DesignUI/CommonStyles";
import { ITableRowTestValue, TableRowTestContext } from "../../Common/TableRowTestContext";
import { PassedTestRow } from "../../CommonStyles";
import { XResultCell } from "../../CommonUI/XResultCell";
import { RuleTableRuleCell } from "./RuleTableRuleCell";
export const XRuleTableRow = (props) => {
    const { rowIndex, ruleDefinition, row, editContext } = props;
    const testContext = React.useContext(TestContext);
    const rowtestitem = testContext === null || testContext === void 0 ? void 0 : testContext.findItem(row._id);
    let testValue;
    if (rowtestitem && !rowtestitem.isError) {
        testValue = rowtestitem.result === "false" ? ITableRowTestValue.FAILED : ITableRowTestValue.PASSED;
    }
    return (_jsxs(TableRowTestContext.Provider, Object.assign({ value: testValue }, { children: [(rowtestitem === null || rowtestitem === void 0 ? void 0 : rowtestitem.result) === "true" ? (_jsx(PassedTestRow, { "data-testid": `passedtestrow`, columnsSpan: ruleDefinition.ruleColumns.length + ruleDefinition.resultColumns.length + 4, y: rowIndex + 2 }, void 0)) : null,
            _jsxs(RuleTableIndexColumn, Object.assign({ y: rowIndex + 2, x: 0, isTestPassed: testValue === ITableRowTestValue.PASSED }, { children: [(rowtestitem === null || rowtestitem === void 0 ? void 0 : rowtestitem.result) === "true" ? _jsx(ApplyIcon, {}, void 0) : null,
                    (rowtestitem === null || rowtestitem === void 0 ? void 0 : rowtestitem.result) === "false" ? _jsx(CloseRedIcon, {}, void 0) : null, rowIndex + 1] }), void 0),
            ruleDefinition.ruleColumns.map((col, idx) => (_createElement(RuleTableRuleCell, Object.assign({ cell: row.ruleCells[col._id], rule: col }, props, { key: idx, cellIndex: idx, rowIndex: rowIndex })))),
            _jsx(RuleTableEmptyAddColumn, { isTestPassed: testValue === ITableRowTestValue.PASSED, y: rowIndex + 2, x: ruleDefinition.ruleColumns.length + 1 }, void 0),
            ruleDefinition.resultColumns.map((col, index2) => {
                return (_jsx(ObserveState, { listenTo: col, control: () => (_jsx(XResultCell, { ruleDefinition: ruleDefinition, editContext: editContext, resultCell: row.resultCellsData[col._id], resultColumn: col, rowIndex: rowIndex + 2, cellIndex: ruleDefinition.ruleColumns.length + 2 + index2 }, col._id)) }, col._id));
            }),
            _jsx(RuleTableEmptyAddColumn, { y: rowIndex + 2, x: ruleDefinition.ruleColumns.length + ruleDefinition.resultColumns.length + 2 }, void 0),
            _jsx(RuleTableHeaderActionColumn, Object.assign({ y: rowIndex + 2, x: ruleDefinition.ruleColumns.length + ruleDefinition.resultColumns.length + 3, onClick: (event) => {
                    if (testContext)
                        return;
                    event.stopPropagation();
                    ruleDefinition.removeRow(row);
                    StateManager.propertyChanged(ruleDefinition, "rows");
                } }, { children: !testContext && _jsx(DeleteGrayIcon, {}, void 0) }), void 0)] }), void 0));
};
//# sourceMappingURL=RuleTableRow.js.map