import { AppObjectEntity, getSingletonComponent, } from "@vived/core";
export class ChallengeEntity extends AppObjectEntity {
    static get(appObjects) {
        return getSingletonComponent(ChallengeEntity.type, appObjects);
    }
}
ChallengeEntity.type = "ChallengeEntity";
export function makeChallengeEntity(appObject) {
    return new ChallengeEntityImp(appObject);
}
class ChallengeEntityImp extends ChallengeEntity {
    registerChallenge(challenge) {
        this.challengeLookup.set(challenge.challengeID, challenge);
        this.notifyOnChange();
    }
    get allChallenges() {
        return Array.from(this.challengeLookup.values());
    }
    get selectedChallenge() {
        return this._selectedChallenge.challengeID;
    }
    set selectedChallenge(id) {
        if (id === this._selectedChallenge.challengeID)
            return;
        const desiredChallenge = this.challengeLookup.get(id);
        if (desiredChallenge) {
            this._selectedChallenge = desiredChallenge;
            this.notifyOnChange();
        }
        else {
            this.warn(`Challenge ${id} not register`);
        }
    }
    get selectedChallengeName() {
        return this._selectedChallenge.name;
    }
    get selectedChallengeConsumerHelp() {
        return this._selectedChallenge.consumerHelpText;
    }
    get selectedChallengeAuthorHelp() {
        return this._selectedChallenge.authorHelpText;
    }
    get selectedChallengeHeading() {
        return this._selectedChallenge.helpHeading;
    }
    constructor(appObject) {
        super(appObject, ChallengeEntity.type);
        this.challengeLookup = new Map();
        this.noChallenge = {
            authorHelpText: "",
            consumerHelpText: "",
            helpHeading: "",
            challengeID: "NONE",
            name: "None",
            reset: () => { },
        };
        this._selectedChallenge = this.noChallenge;
        this.resetSelectedChallenge = () => {
            this._selectedChallenge.reset();
        };
        this.appObjects.registerSingleton(this);
        this.registerChallenge(this.noChallenge);
    }
}
//# sourceMappingURL=ChallengeEntity.js.map