"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SelectedObjectPM = void 0;
exports.makeSelectedObjectPM = makeSelectedObjectPM;
const core_1 = require("@vived/core");
const Selection_1 = require("../Entities/Selection");
class SelectedObjectPM extends core_1.AppObjectPM {
    static get(appObjects) {
        return (0, core_1.getSingletonComponent)(SelectedObjectPM.type, appObjects);
    }
}
exports.SelectedObjectPM = SelectedObjectPM;
SelectedObjectPM.type = "SelectedObjectPM";
function makeSelectedObjectPM(appObj) {
    return new SelectedObjectPMImp(appObj);
}
class SelectedObjectPMImp extends SelectedObjectPM {
    get selection() {
        return this.getCachedSingleton(Selection_1.Selection.type);
    }
    vmsAreEqual(a, b) {
        return a === b;
    }
    constructor(appObject) {
        super(appObject, SelectedObjectPM.type);
        this.onSelectionChange = () => {
            if (!this.selection)
                return;
            this.doUpdateView(this.selection.selectedObjectId);
        };
        this.selection?.addChangeObserver(this.onSelectionChange);
        this.onSelectionChange();
        this.appObjects.registerSingleton(this);
    }
}
//# sourceMappingURL=SelectedObjectPM.js.map