"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
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 mobx_1 = require("mobx");
const PiModel_1 = require("../language/PiModel");
const Box_1 = require("./boxes/Box");
const PiEditor_1 = require("../editor/PiEditor");
const BalanceTreeUtils_1 = require("../util/BalanceTreeUtils");
const PiLogging_1 = require("../util/PiLogging");
const PiUtils_1 = require("../util/PiUtils");
const LOGGER = new PiLogging_1.PiLogger("InternalBehavior");
class InternalBehavior {
    constructor() {
        this.activeInBoxRoles = [];
    }
}
exports.InternalBehavior = InternalBehavior;
class InternalBinaryBehavior extends InternalBehavior {
    constructor(initializer) {
        super();
        PiUtils_1.PiUtils.initializeObject(this, initializer);
    }
    execute(box, aliasId, editor) {
        return __awaiter(this, void 0, void 0, function* () {
            LOGGER.info(this, "execute binary expression alias ok");
            const selected = BalanceTreeUtils_1.BTREE.insertBinaryExpression(this.expressionBuilder(box, aliasId, editor), box, editor);
            editor.selectElement(selected.element, selected.boxRoleToSelect, this.caretPosition);
        });
    }
}
__decorate([
    mobx_1.action,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Box_1.Box, String, PiEditor_1.PiEditor]),
    __metadata("design:returntype", Promise)
], InternalBinaryBehavior.prototype, "execute", null);
exports.InternalBinaryBehavior = InternalBinaryBehavior;
class InternalExpressionBehavior extends InternalBehavior {
    constructor(initializer) {
        super();
        PiUtils_1.PiUtils.initializeObject(this, initializer);
    }
    execute(box, aliasId, editor) {
        return __awaiter(this, void 0, void 0, function* () {
            LOGGER.info(this, "execute expression alias ok");
            const selected = this.expressionBuilder(box, aliasId, editor);
            PiUtils_1.PiUtils.CHECK(PiModel_1.isPiExpression(selected), "execute: expecting new element to be a PiExpression");
            yield editor.selectElement(selected, this.boxRoleToSelect, this.caretPosition);
        });
    }
}
__decorate([
    mobx_1.action,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Box_1.Box, String, PiEditor_1.PiEditor]),
    __metadata("design:returntype", Promise)
], InternalExpressionBehavior.prototype, "execute", null);
exports.InternalExpressionBehavior = InternalExpressionBehavior;
class InternalCustomBehavior extends InternalBehavior {
    constructor(initializer) {
        super();
        PiUtils_1.PiUtils.initializeObject(this, initializer);
    }
    execute(box, aliasId, editor) {
        return __awaiter(this, void 0, void 0, function* () {
            LOGGER.info(this, "execute custom alias ok");
            const selected = this.action(box, aliasId, editor);
            if (selected) {
                yield editor.selectElement(selected, this.boxRoleToSelect, this.caretPosition);
            }
        });
    }
}
__decorate([
    mobx_1.action,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Box_1.Box, String, PiEditor_1.PiEditor]),
    __metadata("design:returntype", Promise)
], InternalCustomBehavior.prototype, "execute", null);
exports.InternalCustomBehavior = InternalCustomBehavior;
//# sourceMappingURL=InternalBehavior.js.map