import { AppObjectPM, getSingletonComponent, } from "@vived/core";
import { Vector2 } from "@vived/core";
import { LabelDropDragMode, LabelDropRepo } from "../Entities/LabelDropRepo";
export class LabelDropDragItemPM extends AppObjectPM {
    static get(appObjects) {
        return getSingletonComponent(LabelDropDragItemPM.type, appObjects);
    }
}
LabelDropDragItemPM.type = "LabelDropDragItemPM";
export function makeLabelDropDragItemPM(appObject) {
    return new LabelDropDragItemPMImp(appObject);
}
class LabelDropDragItemPMImp extends LabelDropDragItemPM {
    get labelDropRepo() {
        return this.getCachedSingleton(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 (!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 = { ...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();
    }
}
export const defaultLabelDropDragItemVM = {
    id: undefined,
    label: "",
    show: false,
    mode: LabelDropDragMode.SCREEN,
    resultIsCorrect: undefined,
    alpha: 0,
    screenPosition: new Vector2(0, 0),
};
//# sourceMappingURL=LabelDropDragItemPM.js.map