"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.IntersectionRuleDesigner = 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 ObserveState_1 = require("../../../CommonUI/StateManagement/ObserveState");
const StateManager_1 = require("@appglue/common/dist/Common/StateManager");
const CommonStyles_1 = require("../../DesignUI/CommonStyles");
const Notification_1 = require("../../../CommonUI/BuilderUI/Notification");
const LinkingDataDialog_1 = require("../../DesignUI/LinkingDataDialog");
const IntersectionRuleHeader_1 = require("./IntersectionRuleHeader");
const IntersectionRuleRow_1 = require("./IntersectionRuleRow");
const DataTypePicker_1 = require("../../../CommonUI/DataTypePicker");
const ValidationInformation_1 = require("../../DesignUI/ValidationInformation");
const TestContext_1 = require("../../../CommonUI/Testing/TestContext");
const TestResult_1 = require("../../../CommonUI/Testing/TestResult");
const IntersectionRuleDesigner = (props) => {
    const { ruleDefinition, editContext } = props;
    const testContext = react_1.default.useContext(TestContext_1.TestContext);
    const onAddNewYAxisRule = () => {
        ruleDefinition.addYAxisExpression();
        StateManager_1.StateManager.propertyChanged(ruleDefinition, "yaxisExpressions");
    };
    if (testContext) {
        return ((0, jsx_runtime_1.jsxs)(CommonStyles_1.RuleEditorInTester, { children: [(0, jsx_runtime_1.jsxs)(CommonStyles_1.RuleEditorRender, { columnCount: ruleDefinition.xaxisExpressions.length + 1, columnsGap: 6, rowsGap: 6, children: [(0, jsx_runtime_1.jsx)(IntersectionRuleHeader_1.IntersectionRuleHeader, { ruleDefinition: ruleDefinition, expressions: ruleDefinition.xaxisExpressions }), (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: ruleDefinition.yaxisExpressions.map((yaxisExp, index) => ((0, jsx_runtime_1.jsx)(IntersectionRuleRow_1.IntersectionRuleRow, { yexpression: yaxisExp, expressions: ruleDefinition.xaxisExpressions, y: index, ruleDefinition: ruleDefinition }, yaxisExp._id))) }), (0, jsx_runtime_1.jsx)(CommonStyles_1.RuleTableEmptyIndexColumn, { "data-testid": "btn-intersectionrule-row-add", disabled: !ruleDefinition.canChangeOutputs }), (0, jsx_runtime_1.jsx)(CommonStyles_1.RuleTableEmptyColumn, {}), (0, jsx_runtime_1.jsx)("div", {}), ruleDefinition.xaxisExpressions.map((_, idx) => ((0, jsx_runtime_1.jsx)(CommonStyles_1.RuleTableEmptyColumn, {}, idx))), (0, jsx_runtime_1.jsx)(CommonStyles_1.RuleTableEmptyAddColumn, {})] }), (0, jsx_runtime_1.jsx)(TestResult_1.TestResult, { executableId: ruleDefinition._id })] }));
    }
    return ((0, jsx_runtime_1.jsxs)(CommonStyles_1.RuleDesignerRender, { children: [(0, jsx_runtime_1.jsx)(CommonStyles_1.RuleToolbarRender, { children: (0, jsx_runtime_1.jsx)(DataTypePicker_1.DataTypePicker, { dataDef: ruleDefinition.resultType, readonly: !ruleDefinition.canChangeOutputs, width: "150px", label: "Rule Result Type:", updateCallback: (newType) => {
                        ruleDefinition.setTypeResults(newType);
                        StateManager_1.StateManager.propertyChanged(ruleDefinition, "resultType");
                    } }) }), (0, jsx_runtime_1.jsx)(ObserveState_1.ObserveState, { listenTo: ruleDefinition, properties: ["xaxisExpressions", "resultType"], control: () => {
                    return ((0, jsx_runtime_1.jsxs)(CommonStyles_1.RuleEditorRender, { columnCount: ruleDefinition.xaxisExpressions.length + 1, children: [(0, jsx_runtime_1.jsx)(IntersectionRuleHeader_1.IntersectionRuleHeader, { ruleDefinition: ruleDefinition, expressions: ruleDefinition.xaxisExpressions }), (0, jsx_runtime_1.jsx)(ObserveState_1.ObserveState, { listenTo: ruleDefinition, properties: ["yaxisExpressions"], control: () => {
                                    return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: ruleDefinition.yaxisExpressions.map((yaxisExp, index) => ((0, jsx_runtime_1.jsx)(IntersectionRuleRow_1.IntersectionRuleRow, { yexpression: yaxisExp, expressions: ruleDefinition.xaxisExpressions, y: index, ruleDefinition: ruleDefinition }, yaxisExp._id))) }));
                                } }), (0, jsx_runtime_1.jsx)(ObserveState_1.ObserveState, { listenTo: ruleDefinition, properties: ["canChangeOutputs"], control: () => ((0, jsx_runtime_1.jsx)(CommonStyles_1.RuleTableEmptyIndexColumn, { onClick: onAddNewYAxisRule, "data-testid": "btn-intersectionrule-row-add", disabled: !ruleDefinition.canChangeOutputs, children: (0, jsx_runtime_1.jsx)(PlusGrayIcon_1.PlusGrayIcon, {}) })) }), (0, jsx_runtime_1.jsx)(CommonStyles_1.RuleTableEmptyColumn, {}), (0, jsx_runtime_1.jsx)("div", {}), ruleDefinition.xaxisExpressions.map((_, idx) => ((0, jsx_runtime_1.jsx)(CommonStyles_1.RuleTableEmptyColumn, {}, idx))), (0, jsx_runtime_1.jsx)(CommonStyles_1.RuleTableEmptyAddColumn, {})] }));
                } }), (0, jsx_runtime_1.jsx)(ObserveState_1.ObserveState, { listenTo: ruleDefinition, control: () => (0, jsx_runtime_1.jsx)(ValidationInformation_1.ValidationInformation, { provider: ruleDefinition }) }), (0, jsx_runtime_1.jsx)(Notification_1.Notification, { editContext: editContext }), (0, jsx_runtime_1.jsx)(LinkingDataDialog_1.LinkingDataDialog, { editContext: editContext })] }));
};
exports.IntersectionRuleDesigner = IntersectionRuleDesigner;
//# sourceMappingURL=IntersectionRuleDesigner.js.map