import { AppObjectPM, getSingletonComponent, } from "@vived/core";
import { BaseAppState } from "../../BaseApp";
import { ChallengeEntity } from "../Entities/ChallengeEntity";
export class ChallengeConsumerHelpPM extends AppObjectPM {
    static get(appObjects) {
        return getSingletonComponent(ChallengeConsumerHelpPM.type, appObjects);
    }
}
ChallengeConsumerHelpPM.type = "ChallengeHelpPM";
export function makeChallengeConsumerHelpPM(appObject) {
    return new ChallengeConsumerHelpPMImp(appObject);
}
class ChallengeConsumerHelpPMImp extends ChallengeConsumerHelpPM {
    get challengeEntity() {
        return this.getCachedSingleton(ChallengeEntity.type);
    }
    get baseApp() {
        return this.getCachedSingleton(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);
    }
}
export const defaultChallengeConsumerHelpVM = {
    show: false,
    heading: "",
    text: "",
};
//# sourceMappingURL=ChallengeConsumerHelpPM.js.map