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 { XValueTableRuleCell } from "./ValueTableRuleCell";
export const XValueTableRow = ({ ruleDefinition, row, index, editContext }) => {
    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.columns.length + ruleDefinition.resultColumns.length + 4, y: index + 3 }, void 0)) : null,
            _jsxs(RuleTableIndexColumn, Object.assign({ y: index + 3, 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, index + 1] }), void 0),
            row.cells.map((cell, index2) => (_jsx(ObserveState, { listenTo: cell, properties: ["dataType"], control: () => (_jsx(XValueTableRuleCell, { ruleDefinition: ruleDefinition, cell: cell, editContext: editContext, rowIndex: index, cellIndex: index2 }, void 0)) }, index2))),
            _jsx(RuleTableEmptyAddColumn, { isTestPassed: testValue === ITableRowTestValue.PASSED, y: index + 3, x: ruleDefinition.columns.length + 1 }, void 0),
            ruleDefinition.resultColumns.map((col, index2) => {
                return (_jsx(ObserveState, { listenTo: col, properties: ["dataType"], control: () => (_jsx(XResultCell, { editContext: editContext, resultColumn: col, resultCell: row.resultCellsData[col._id], ruleDefinition: ruleDefinition, rowIndex: index + 3, cellIndex: ruleDefinition.columns.length + 2 + index2 }, void 0)) }, col._id));
            }),
            _jsx(RuleTableEmptyAddColumn, { y: index + 3, x: ruleDefinition.columns.length + ruleDefinition.resultColumns.length + 2 }, void 0),
            _jsx(RuleTableHeaderActionColumn, Object.assign({ y: index + 3, x: ruleDefinition.columns.length + ruleDefinition.resultColumns.length + 3, onClick: (event) => {
                    if (testContext)
                        return null;
                    event.stopPropagation();
                    ruleDefinition.removeRow(row);
                    StateManager.propertyChanged(ruleDefinition, "rows");
                } }, { children: testContext ? null : _jsx(DeleteGrayIcon, {}, void 0) }), void 0)] }), void 0));
};
//# sourceMappingURL=ValueTableRow.js.map