"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FeatureFlagsPM = void 0;
exports.makeFeatureFlagsPM = makeFeatureFlagsPM;
const core_1 = require("@vived/core");
const FeatureFlagEntity_1 = require("../Entity/FeatureFlagEntity");
class FeatureFlagsPM extends core_1.AppObjectPM {
    static get(appObjects) {
        return (0, core_1.getSingletonComponent)(FeatureFlagsPM.type, appObjects);
    }
}
exports.FeatureFlagsPM = FeatureFlagsPM;
FeatureFlagsPM.type = "FeatureFlagsPM";
function makeFeatureFlagsPM(appObject) {
    return new FeatureFlagsPMImp(appObject);
}
class FeatureFlagsPMImp extends FeatureFlagsPM {
    get featureFlagsEntity() {
        return this.getCachedSingleton(FeatureFlagEntity_1.FeatureFlagsEntity.type);
    }
    vmsAreEqual(a, b) {
        if (a.length !== b.length)
            return false;
        let areEqual = true;
        a.forEach((flagA, i) => {
            const flagB = b[i];
            if (flagA !== flagB) {
                areEqual = false;
            }
        });
        return areEqual;
    }
    constructor(appObject) {
        super(appObject, FeatureFlagsPM.type);
        this.onEntityChange = () => {
            if (!this.featureFlagsEntity)
                return;
            this.doUpdateView(this.featureFlagsEntity.flags);
        };
        this.onEntityChange();
        this.featureFlagsEntity?.addChangeObserver(this.onEntityChange);
        this.appObjects.registerSingleton(this);
    }
}
//# sourceMappingURL=FeatureFlagsPM.js.map