"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
const Keys = require("../../util/Keys");
const util_1 = require("../../util");
const axios_1 = require("axios");
const testmodel_1 = require("../testmodel");
const CoreTestModel_1 = require("../testmodel/CoreTestModel");
const CoreTestEntity_1 = require("../testmodel/domain/CoreTestEntity");
const CoreTestSumExpression_1 = require("../testmodel/expressions/CoreTestSumExpression");
const LOGGER = new util_1.PiLogger("CoreTestActions");
const EXPRESSION_CREATORS = [
    {
        trigger: '"',
        activeInBoxRoles: [util_1.EXPRESSION_PLACEHOLDER],
        expressionBuilder: (box, trigger, editor) => {
            return new testmodel_1.CoreTestStringLiteralExpression();
        },
        boxRoleToSelect: "string-value"
    },
    {
        trigger: /[0-9]/,
        activeInBoxRoles: [util_1.EXPRESSION_PLACEHOLDER],
        expressionBuilder: (box, trigger, editor) => {
            util_1.PiUtils.CHECK(typeof trigger === "string", "Trigger for numeric literal should be a string");
            return testmodel_1.CoreTestNumberLiteralExpression.create(trigger);
        },
        boxRoleToSelect: "num-literal-value",
        caretPosition: util_1.PiCaret.RIGHT_MOST
    },
    {
        trigger: "sum",
        activeInBoxRoles: [util_1.EXPRESSION_PLACEHOLDER],
        expressionBuilder: (box, trigger, editor) => {
            return new CoreTestSumExpression_1.CoreTestSumExpression();
        },
        boxRoleToSelect: util_1.EXPRESSION_PLACEHOLDER,
        caretPosition: util_1.PiCaret.RIGHT_MOST
    }
];
const BINARY_EXPRESSION_CREATORS = [
    {
        trigger: "+",
        activeInBoxRoles: [
            util_1.LEFT_MOST,
            util_1.RIGHT_MOST,
            util_1.EXPRESSION_PLACEHOLDER,
            util_1.BEFORE_BINARY_OPERATOR,
            util_1.AFTER_BINARY_OPERATOR
        ],
        expressionBuilder: (box, trigger, editor) => {
            return new testmodel_1.CoreTestPlusExpression();
        },
        boxRoleToSelect: util_1.EXPRESSION_PLACEHOLDER
    },
    {
        trigger: ">",
        activeInBoxRoles: [
            util_1.LEFT_MOST,
            util_1.RIGHT_MOST,
            util_1.EXPRESSION_PLACEHOLDER,
            util_1.BEFORE_BINARY_OPERATOR,
            util_1.AFTER_BINARY_OPERATOR
        ],
        expressionBuilder: (box, trigger, editor) => {
            return testmodel_1.CoretestComparisonExpression.create(">");
        },
        boxRoleToSelect: util_1.EXPRESSION_PLACEHOLDER
    },
    {
        trigger: "<=",
        activeInBoxRoles: [
            util_1.LEFT_MOST,
            util_1.RIGHT_MOST,
            util_1.EXPRESSION_PLACEHOLDER,
            util_1.BEFORE_BINARY_OPERATOR,
            util_1.AFTER_BINARY_OPERATOR
        ],
        expressionBuilder: (box, trigger, editor) => {
            return testmodel_1.CoretestComparisonExpression.create("<=");
        },
        boxRoleToSelect: util_1.EXPRESSION_PLACEHOLDER
    },
    {
        trigger: "<",
        activeInBoxRoles: [
            util_1.LEFT_MOST,
            util_1.RIGHT_MOST,
            util_1.EXPRESSION_PLACEHOLDER,
            util_1.BEFORE_BINARY_OPERATOR,
            util_1.AFTER_BINARY_OPERATOR
        ],
        expressionBuilder: (box) => {
            return testmodel_1.CoretestComparisonExpression.create("<");
        },
        boxRoleToSelect: util_1.EXPRESSION_PLACEHOLDER
    },
    {
        trigger: ">=",
        activeInBoxRoles: [
            util_1.LEFT_MOST,
            util_1.RIGHT_MOST,
            util_1.EXPRESSION_PLACEHOLDER,
            util_1.BEFORE_BINARY_OPERATOR,
            util_1.AFTER_BINARY_OPERATOR
        ],
        expressionBuilder: (box) => {
            return testmodel_1.CoretestComparisonExpression.create(">=");
        },
        boxRoleToSelect: util_1.EXPRESSION_PLACEHOLDER
    },
    {
        trigger: "==",
        activeInBoxRoles: [
            util_1.LEFT_MOST,
            util_1.RIGHT_MOST,
            util_1.EXPRESSION_PLACEHOLDER,
            util_1.BEFORE_BINARY_OPERATOR,
            util_1.AFTER_BINARY_OPERATOR
        ],
        expressionBuilder: (box) => {
            return testmodel_1.CoretestComparisonExpression.create("==");
        },
        boxRoleToSelect: util_1.EXPRESSION_PLACEHOLDER
    },
    {
        trigger: "and",
        activeInBoxRoles: [
            util_1.LEFT_MOST,
            util_1.RIGHT_MOST,
            util_1.EXPRESSION_PLACEHOLDER,
            util_1.BEFORE_BINARY_OPERATOR,
            util_1.AFTER_BINARY_OPERATOR
        ],
        expressionBuilder: (box) => {
            return new testmodel_1.CoreTestAndExpression();
        },
        boxRoleToSelect: util_1.EXPRESSION_PLACEHOLDER
    },
    {
        trigger: "or",
        activeInBoxRoles: [
            util_1.LEFT_MOST,
            util_1.RIGHT_MOST,
            util_1.EXPRESSION_PLACEHOLDER,
            util_1.BEFORE_BINARY_OPERATOR,
            util_1.AFTER_BINARY_OPERATOR
        ],
        expressionBuilder: (box) => {
            return new testmodel_1.CoreTestOrExpression();
        },
        boxRoleToSelect: util_1.EXPRESSION_PLACEHOLDER
    },
    {
        trigger: "/",
        activeInBoxRoles: [
            util_1.LEFT_MOST,
            util_1.RIGHT_MOST,
            util_1.EXPRESSION_PLACEHOLDER,
            util_1.BEFORE_BINARY_OPERATOR,
            util_1.AFTER_BINARY_OPERATOR
        ],
        expressionBuilder: (box) => {
            return new testmodel_1.CoreTestDivideExpression();
        },
        boxRoleToSelect: util_1.EXPRESSION_PLACEHOLDER
    },
    {
        trigger: "*",
        activeInBoxRoles: [
            util_1.LEFT_MOST,
            util_1.RIGHT_MOST,
            util_1.EXPRESSION_PLACEHOLDER,
            util_1.BEFORE_BINARY_OPERATOR,
            util_1.AFTER_BINARY_OPERATOR
        ],
        expressionBuilder: (box) => {
            return new testmodel_1.CoreTestMultiplyExpression();
        },
        boxRoleToSelect: util_1.EXPRESSION_PLACEHOLDER
    }
];
const CUSTOM_BEHAVIORS = [
    {
        trigger: "function",
        activeInBoxRoles: ["end-of-function-list"],
        action: (box, trigger, editor) => {
            var model = box.element;
            const fun = new testmodel_1.CoreTestFunction();
            model.functions.push(fun);
            return fun;
        },
        boxRoleToSelect: "fun-name"
    },
    {
        activeInBoxRoles: ["end-of-entity-list"],
        trigger: "entity",
        action: (box, trigger, ed) => {
            var model = box.element;
            const entity = new CoreTestEntity_1.CoreTestEntity();
            model.units[0].entities.push(entity);
            return entity;
        },
        boxRoleToSelect: "entity-name"
    },
    {
        trigger: "attribute",
        activeInBoxRoles: ["end-of-attribute-list"],
        action: (box, trigger, editor) => {
            var entity = box.element;
            const attribute = new testmodel_1.CoreTestAttribute();
            entity.attributes.push(attribute);
            return attribute;
        },
        boxRoleToSelect: "attribute-name"
    },
    {
        trigger: "!!",
        activeInBoxRoles: [util_1.EXPRESSION_PLACEHOLDER],
        action: (box, trigger, editor) => {
            LOGGER.log("Action done");
            return null;
        }
    },
    {
        trigger: "a",
        activeInBoxRoles: ["string-value"],
        action: (box, trigger, editor) => {
            LOGGER.log("========================== Action done");
            return null;
        }
    }
];
const KEYBOARD = [
    {
        trigger: { meta: util_1.MetaKey.Shift, keyCode: Keys.ENTER },
        activeInBoxRoles: [util_1.EXPRESSION_PLACEHOLDER],
        action: (box, key, editor) => {
            LOGGER.log("Ketyboard ENTER SHIFT Action done");
            return null;
        }
    },
    {
        trigger: { meta: util_1.MetaKey.None, keyCode: Keys.ENTER },
        activeInBoxRoles: ["list-for-entities"],
        action: (box, key, editor) => __awaiter(void 0, void 0, void 0, function* () {
            LOGGER.log("list================= -for-entities ");
            const entity = box.element;
            util_1.PiUtils.CHECK(entity instanceof CoreTestEntity_1.CoreTestEntity, "current element should be an entity but it is " + entity);
            const proc = entity.piContainer();
            const parent = proc.container;
            util_1.PiUtils.CHECK(parent[proc.propertyName][proc.propertyIndex] === entity);
            util_1.PiUtils.CHECK(parent instanceof CoreTestModel_1.CoreTestModel);
            if (parent instanceof CoreTestModel_1.CoreTestModel) {
                const e = new CoreTestEntity_1.CoreTestEntity();
                parent.units[0].entities.splice(proc.propertyIndex + 1, 0, e);
                yield editor.selectElement(e, "entity-name");
            }
            return null;
        })
    },
    {
        trigger: { meta: util_1.MetaKey.Ctrl, keyCode: Keys.CHARACTER_A },
        activeInBoxRoles: ["start-quote"],
        action: (box, key, editor) => {
            LOGGER.log("========================== Action Ctrl-a done");
            return null;
        }
    },
    {
        trigger: { meta: util_1.MetaKey.None, keyCode: Keys.CHARACTER_A },
        activeInBoxRoles: ["end-quote"],
        action: (box, key, editor) => {
            LOGGER.log("========================== Action 'a' done");
            return null;
        }
    },
    {
        trigger: { meta: util_1.MetaKey.None, keyCode: Keys.ENTER },
        activeInBoxRoles: ["end-of-entity-list"],
        action: (box, key, editor) => {
            var model = box.element;
            const entity = CoreTestEntity_1.CoreTestEntity.create("");
            model.units[0].entities.push(entity);
            return Promise.resolve(entity);
        },
        boxRoleToSelect: "entity-name"
    },
];
class CoreTestActions {
    constructor() {
        this.expressionCreators = EXPRESSION_CREATORS;
        this.binaryExpressionCreators = BINARY_EXPRESSION_CREATORS;
        this.customBehaviors = CUSTOM_BEHAVIORS;
        this.keyboardActions = KEYBOARD;
    }
}
exports.CoreTestActions = CoreTestActions;
function getModelList() {
    return __awaiter(this, void 0, void 0, function* () {
        console.log("getModelList");
        try {
            const res = yield axios_1.default.get(`http://127.0.0.1:3001/getModelList`);
            console.log(res.data + " is " + typeof res.data);
            console.log(JSON.stringify(res.data));
            return res.data;
        }
        catch (e) {
            console.log("Error " + e.toString());
        }
        return {};
    });
}
exports.getModelList = getModelList;
//# sourceMappingURL=CoreTestActions.js.map