"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.defaultLabelDropDragItemVM = exports.LabelDropDragItemPM = void 0;
exports.makeLabelDropDragItemPM = makeLabelDropDragItemPM;
const core_1 = require("@vived/core");
const core_2 = require("@vived/core");
const LabelDropRepo_1 = require("../Entities/LabelDropRepo");
class LabelDropDragItemPM extends core_1.AppObjectPM {
    static get(appObjects) {
        return (0, core_1.getSingletonComponent)(LabelDropDragItemPM.type, appObjects);
    }
}
exports.LabelDropDragItemPM = LabelDropDragItemPM;
LabelDropDragItemPM.type = "LabelDropDragItemPM";
function makeLabelDropDragItemPM(appObject) {
    return new LabelDropDragItemPMImp(appObject);
}
class LabelDropDragItemPMImp extends LabelDropDragItemPM {
    get labelDropRepo() {
        return this.getCachedSingleton(LabelDropRepo_1.LabelDropRepo.type);
    }
    vmsAreEqual(a, b) {
        if (a.id !== b.id)
            return false;
        if (a.label !== b.label)
            return false;
        if (a.show !== b.show)
            return false;
        if (a.mode !== b.mode)
            return false;
        if (a.resultIsCorrect !== b.resultIsCorrect)
            return false;
        if (a.alpha !== b.alpha)
            return false;
        if (!core_2.Vector2.Equal(a.screenPosition, b.screenPosition))
            return false;
        return true;
    }
    constructor(appObject) {
        super(appObject, LabelDropDragItemPM.type);
        this.handleEntityChange = () => {
            if (!this.labelDropRepo)
                return;
            if (!this.labelDropRepo.draggingID) {
                const notDraggingVM = { ...exports.defaultLabelDropDragItemVM };
                notDraggingVM.mode = this.labelDropRepo.dragMode;
                this.doUpdateView(notDraggingVM);
                return;
            }
            const dragItem = this.labelDropRepo.getForAppObject(this.labelDropRepo.draggingID);
            const showDragItem = this.labelDropRepo.dragAlpha > 0;
            const vm = {
                id: this.labelDropRepo.draggingID,
                label: dragItem?.labelEntity.display ?? "",
                show: showDragItem,
                mode: this.labelDropRepo.dragMode,
                resultIsCorrect: this.labelDropRepo.resultIsCorrect,
                alpha: this.labelDropRepo.dragAlpha,
                screenPosition: this.labelDropRepo.screenPosition,
            };
            this.doUpdateView(vm);
        };
        this.dispose = () => {
            super.dispose();
            this.labelDropRepo?.removeChangeObserver(this.handleEntityChange);
            this.labelDropRepo?.removeOnDisposeObserver(this.dispose);
        };
        this.labelDropRepo?.addChangeObserver(this.handleEntityChange);
        this.appObjects.registerSingleton(this);
        this.handleEntityChange();
    }
}
exports.defaultLabelDropDragItemVM = {
    id: undefined,
    label: "",
    show: false,
    mode: LabelDropRepo_1.LabelDropDragMode.SCREEN,
    resultIsCorrect: undefined,
    alpha: 0,
    screenPosition: new core_2.Vector2(0, 0),
};
//# sourceMappingURL=LabelDropDragItemPM.js.map