"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.defaultChallengeConsumerHelpVM = exports.ChallengeConsumerHelpPM = void 0;
exports.makeChallengeConsumerHelpPM = makeChallengeConsumerHelpPM;
const core_1 = require("@vived/core");
const BaseApp_1 = require("../../BaseApp");
const ChallengeEntity_1 = require("../Entities/ChallengeEntity");
class ChallengeConsumerHelpPM extends core_1.AppObjectPM {
    static get(appObjects) {
        return (0, core_1.getSingletonComponent)(ChallengeConsumerHelpPM.type, appObjects);
    }
}
exports.ChallengeConsumerHelpPM = ChallengeConsumerHelpPM;
ChallengeConsumerHelpPM.type = "ChallengeHelpPM";
function makeChallengeConsumerHelpPM(appObject) {
    return new ChallengeConsumerHelpPMImp(appObject);
}
class ChallengeConsumerHelpPMImp extends ChallengeConsumerHelpPM {
    get challengeEntity() {
        return this.getCachedSingleton(ChallengeEntity_1.ChallengeEntity.type);
    }
    get baseApp() {
        return this.getCachedSingleton(BaseApp_1.BaseAppState.type);
    }
    vmsAreEqual(a, b) {
        if (a.heading !== b.heading)
            return false;
        if (a.show !== b.show)
            return false;
        if (a.text !== b.text)
            return false;
        return true;
    }
    constructor(appObject) {
        super(appObject, ChallengeConsumerHelpPM.type);
        this.onEntityChange = () => {
            if (!this.challengeEntity || !this.baseApp)
                return;
            const text = this.challengeEntity.selectedChallengeConsumerHelp;
            const heading = this.challengeEntity.selectedChallengeHeading;
            let challengeHelpShow = true;
            if (!text || !heading || this.baseApp.isReviewing) {
                challengeHelpShow = false;
            }
            const vm = {
                show: challengeHelpShow,
                heading,
                text,
            };
            this.doUpdateView(vm);
        };
        this.baseApp?.addChangeObserver(this.onEntityChange);
        this.challengeEntity?.addChangeObserver(this.onEntityChange);
        this.onEntityChange();
        this.appObjects.registerSingleton(this);
    }
}
exports.defaultChallengeConsumerHelpVM = {
    show: false,
    heading: "",
    text: "",
};
//# sourceMappingURL=ChallengeConsumerHelpPM.js.map