"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);
};
Object.defineProperty(exports, "__esModule", { value: true });
const mobx_1 = require("mobx");
class OrderedList {
    constructor() {
        this.elements = [];
    }
    toArray() {
        return this.elements;
    }
    add(name, p) {
        this.elements.push({ name: name, element: p });
    }
    length() {
        return this.elements.length;
    }
    toFront(name) {
        let index = this.elements.findIndex(np => np.name === name);
        if (index < 0) {
            return;
        }
        const tobeMoved = this.elements[index];
        for (let i = index; i > 0; i--) {
            this.elements[i] = this.elements[i - 1];
        }
        this.elements[0] = tobeMoved;
    }
    toBack(name) {
        let index = this.elements.findIndex(np => np.name === name);
        if (index < 0) {
            return;
        }
        const size = this.elements.length;
        const tobeMoved = this.elements[index];
        for (let i = index; i < size - 1; i++) {
            this.elements[i] = this.elements[i + 1];
        }
        this.elements[0] = tobeMoved;
    }
    get(index) {
        return this.elements[index];
    }
    [Symbol.iterator]() {
        return new OrderedListIterator(this);
    }
}
__decorate([
    mobx_1.observable,
    __metadata("design:type", Array)
], OrderedList.prototype, "elements", void 0);
exports.OrderedList = OrderedList;
class OrderedListIterator {
    constructor(list) {
        this.index = 0;
        this.list = list;
    }
    next(value) {
        const l = this.list.length();
        if (this.index < l) {
            return { done: false, value: this.list.get(this.index++).element };
        }
        else {
            return { done: true, value: undefined };
        }
    }
}
exports.OrderedListIterator = OrderedListIterator;
//# sourceMappingURL=OrderedList.js.map