import { AppObjectPM, getSingletonComponent, } from "@vived/core";
import { ChannelModelRepo } from "../Entities";
export class ActiveModelObjectListPM extends AppObjectPM {
    static get(appObjects) {
        return getSingletonComponent(ActiveModelObjectListPM.type, appObjects);
    }
}
ActiveModelObjectListPM.type = "ActiveModelObjectListPM";
export function makeActiveModelObjectListPM(appObject) {
    return new ActiveModelObjectListPMImp(appObject);
}
class ActiveModelObjectListPMImp extends ActiveModelObjectListPM {
    get repo() {
        return this.getCachedSingleton(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