"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ObjectPickEntity = void 0;
exports.makeObjectPickEntity = makeObjectPickEntity;
const core_1 = require("@vived/core");
class ObjectPickEntity extends core_1.AppObjectEntity {
    constructor() {
        super(...arguments);
        this.challengeID = "OBJECT_PICK";
        this.authorHelpText = "Challenge the user to pick on specific object.";
        this.consumerHelpText = "You are being challenged to pick on an object in the scene. Read the question and the pick the object that you think is correct.";
        this.helpHeading = "Object Pick Challenge Help";
        this.name = "Object Pick";
    }
    static get(appObjects) {
        return (0, core_1.getSingletonComponent)(ObjectPickEntity.type, appObjects);
    }
}
exports.ObjectPickEntity = ObjectPickEntity;
ObjectPickEntity.type = "ObjectPick";
function makeObjectPickEntity(appObject) {
    return new ObjectPickImp(appObject);
}
class ObjectPickImp extends ObjectPickEntity {
    get correctObjectIds() {
        return [...this._correctObjectIds];
    }
    get hasSubmitted() {
        return this._submittedId === null ? false : true;
    }
    get isCorrect() {
        if (this._submittedId !== null) {
            return this._correctObjectIds.includes(this._submittedId);
        }
        return false;
    }
    get isSelectingCorrectObjects() {
        return this._memoizedIsSelectingCorrectObjects.val;
    }
    set isSelectingCorrectObjects(val) {
        this._memoizedIsSelectingCorrectObjects.val = val;
    }
    constructor(appObject) {
        super(appObject, ObjectPickEntity.type);
        this._submittedId = null;
        this._correctObjectIds = [];
        this._memoizedIsSelectingCorrectObjects = new core_1.MemoizedBoolean(false, this.notifyOnChange);
        this.addCorrectObjectId = (id) => {
            if (!this._correctObjectIds.includes(id)) {
                this._correctObjectIds.push(id);
                this.notifyOnChange();
            }
        };
        this.removeCorrectObjectId = (id) => {
            const index = this._correctObjectIds.indexOf(id);
            if (index !== -1) {
                this._correctObjectIds.splice(index, 1);
                this.notifyOnChange();
            }
        };
        this.clearCorrectObjectIds = () => {
            this._correctObjectIds = [];
            this._submittedId = null;
            this.notifyOnChange();
        };
        this.submit = (id) => {
            this._submittedId = id;
            this.notifyOnChange();
        };
        this.reset = () => {
            this._submittedId = null;
            this.notifyOnChange();
        };
        this.onAppObjectRemoved = (appObject) => {
            if (this._correctObjectIds.includes(appObject.id)) {
                this.removeCorrectObjectId(appObject.id);
            }
        };
        this.appObjects.addAppObjectRemovedObserver(this.onAppObjectRemoved);
    }
}
//# sourceMappingURL=ObjectPickEntity.js.map