"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ActiveModelObjectListPM = void 0;
exports.makeActiveModelObjectListPM = makeActiveModelObjectListPM;
const core_1 = require("@vived/core");
const Entities_1 = require("../Entities");
class ActiveModelObjectListPM extends core_1.AppObjectPM {
    static get(appObjects) {
        return (0, core_1.getSingletonComponent)(ActiveModelObjectListPM.type, appObjects);
    }
}
exports.ActiveModelObjectListPM = ActiveModelObjectListPM;
ActiveModelObjectListPM.type = "ActiveModelObjectListPM";
function makeActiveModelObjectListPM(appObject) {
    return new ActiveModelObjectListPMImp(appObject);
}
class ActiveModelObjectListPMImp extends ActiveModelObjectListPM {
    get repo() {
        return this.getCachedSingleton(Entities_1.ChannelModelRepo.type);
    }
    vmsAreEqual(a, b) {
        if (a.length !== b.length)
            return false;
        let arraysAreEqual = true;
        a.forEach((aID, i) => {
            if (!arraysAreEqual)
                return;
            const bID = b[i];
            if (aID !== bID) {
                arraysAreEqual = false;
            }
        });
        return arraysAreEqual;
    }
    constructor(appObject) {
        super(appObject, ActiveModelObjectListPM.type);
        this.onEntityChange = () => {
            if (!this.repo)
                return;
            if (this.lastActiveModelID === this.repo.activeModel)
                return;
            let vm = [];
            if (this.repo.activeModel) {
                const model = this.repo.getChannelModel(this.repo.activeModel, false);
                if (model) {
                    vm = model.modelObjectIds;
                    this.lastActiveModelID = this.repo.activeModel;
                }
            }
            else {
                this.lastActiveModelID = "";
            }
            this.doUpdateView(vm);
        };
        this.repo?.addChangeObserver(this.onEntityChange);
        this.onEntityChange();
        this.appObjects.registerSingleton(this);
    }
}
//# sourceMappingURL=ActiveModelObjectListPM.js.map