"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RuleTableTester = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const XExecutableTester_1 = require("../XExecutableTester");
const RuleTableConfiguration_1 = require("@appglue/common/dist/Rule/Table/Rule/RuleTableConfiguration");
const DataDefinition_1 = require("@appglue/common/dist/Common/Data/DataDefinition");
const NumberDataDefinition_1 = require("@appglue/common/dist/Common/Data/Definitions/NumberDataDefinition");
const StringDataDefinition_1 = require("@appglue/common/dist/Common/Data/Definitions/StringDataDefinition");
const ExpressionConfiguration_1 = require("@appglue/common/dist/Expressions/ExpressionConfiguration");
const LessThanExpression_1 = require("@appglue/common/dist/Expressions/Expressions/Logic/LessThanExpression");
const BooleanDataDefinition_1 = require("@appglue/common/dist/Common/Data/Definitions/BooleanDataDefinition");
const NotExpression_1 = require("@appglue/common/dist/Expressions/Expressions/Logic/NotExpression");
const LogicData_1 = require("../../../Expressions/Testing/LogicData");
const StoryData_1 = require("../../StoryBook/StoryData");
const getRuleTableWithData = () => {
    const ruleDefinition = new RuleTableConfiguration_1.RuleTableConfiguration();
    let idatadef = new DataDefinition_1.DataDefinition();
    idatadef.fields.push(new NumberDataDefinition_1.NumberDataDefinition("income"));
    idatadef.fields.push(new BooleanDataDefinition_1.BooleanDataDefinition("isMarried"));
    ruleDefinition.inputData = idatadef;
    for (let fidx in idatadef.fields) {
        let f = idatadef.fields[fidx];
        let ruleColumn;
        if (fidx !== "0") {
            ruleColumn = ruleDefinition.addRuleColumn(f.name);
        }
        else {
            ruleColumn = ruleDefinition.ruleColumns[0];
        }
        ruleColumn.path = f.name;
        ruleColumn.name = f.name;
    }
    let odatadef = new DataDefinition_1.DataDefinition();
    odatadef.fields.push(new StringDataDefinition_1.StringDataDefinition("name"));
    ruleDefinition.executionResult = () => odatadef;
    ruleDefinition.addRow();
    let _exp = new ExpressionConfiguration_1.ExpressionConfiguration();
    let lessThan = new LessThanExpression_1.LessThanExpression();
    lessThan.value1.variableName = "income";
    lessThan.value2.value = 5000;
    ruleDefinition.rows[0].cells[0].expression = new ExpressionConfiguration_1.ExpressionConfiguration();
    ruleDefinition.rows[0].cells[0].expression.expression = lessThan;
    ruleDefinition.rows[0].cells[1].expression = new ExpressionConfiguration_1.ExpressionConfiguration();
    ruleDefinition.rows[0].cells[1].expression.variableName = "isMarried";
    ruleDefinition.rows[0].resultCells[0].value = "Jose Chacin";
    lessThan = new LessThanExpression_1.LessThanExpression();
    lessThan.value2.variableName = "income";
    lessThan.value1.value = 5000;
    ruleDefinition.rows[1].cells[0].expression = new ExpressionConfiguration_1.ExpressionConfiguration();
    ruleDefinition.rows[1].cells[0].expression.expression = lessThan;
    ruleDefinition.rows[1].cells[1].expression = new ExpressionConfiguration_1.ExpressionConfiguration();
    let notExpression = new NotExpression_1.NotExpression();
    notExpression.value1.variableName = "isMarried";
    ruleDefinition.rows[1].cells[1].expression.expression = notExpression;
    ruleDefinition.rows[1].resultCells[0].value = "Bruno Pereira";
    ruleDefinition.defaultResult[ruleDefinition.resultColumns[0]._id].value = "James";
    return ruleDefinition;
};
exports.RuleTableTester = [
    new StoryData_1.StoryNode(() => {
        let ruleDefinition = getRuleTableWithData();
        return (0, jsx_runtime_1.jsx)(XExecutableTester_1.XExecutableTester, { executable: ruleDefinition });
    }, "Test UI", "Rule Table", "Default"),
    new StoryData_1.StoryNode(() => {
        let ruleDefinition = getRuleTableWithData();
        ruleDefinition.allowDefaultResults = false;
        return (0, jsx_runtime_1.jsx)(XExecutableTester_1.XExecutableTester, { executable: ruleDefinition });
    }, "Test UI", "Rule Table", "No Default"),
    new StoryData_1.StoryNode(() => {
        let ruleDefinition = getRuleTableWithData();
        let idatadef = new DataDefinition_1.DataDefinition();
        idatadef.fields.push(new NumberDataDefinition_1.NumberDataDefinition("income"));
        idatadef.fields.push(new BooleanDataDefinition_1.BooleanDataDefinition("isMarried"));
        idatadef.fields.push(new BooleanDataDefinition_1.BooleanDataDefinition("isEmployee"));
        idatadef.fields.push(new BooleanDataDefinition_1.BooleanDataDefinition("isContractor"));
        ruleDefinition.inputData = idatadef;
        ruleDefinition.rows[0].cells[1].expression.expression = (0, LogicData_1.getIfElseSimpleRule)().expression;
        ruleDefinition.setRuleColumn(ruleDefinition.ruleColumns[1], "isContractor");
        return (0, jsx_runtime_1.jsx)(XExecutableTester_1.XExecutableTester, { executable: ruleDefinition });
    }, "Test UI", "Rule Table", "If Then"),
];
//# sourceMappingURL=XExecutableTester.RuleTable-stories.js.map