import { AppObjectUC, getSingletonComponent, } from "@vived/core";
import { PixelToSceneRayUC, SceneRayPickUC } from "../../Babylon/UC";
import { LabelDropRepo } from "../Entities/LabelDropRepo";
export class ToggleLabelDropTargetUC extends AppObjectUC {
    static get(appObjects) {
        return getSingletonComponent(ToggleLabelDropTargetUC.type, appObjects);
    }
}
ToggleLabelDropTargetUC.type = "ToggleLabelDropTargetUC";
export function makeToggleLabelDropTargetUC(appObject) {
    return new ToggleLabelDropTargetUCImp(appObject);
}
class ToggleLabelDropTargetUCImp extends ToggleLabelDropTargetUC {
    get repo() {
        return this.getCachedSingleton(LabelDropRepo.type);
    }
    get sceneRayPick() {
        return this.getCachedSingleton(SceneRayPickUC.type)
            ?.sceneRayPick;
    }
    get pixelToRay() {
        return this.getCachedSingleton(PixelToSceneRayUC.type)
            ?.pixelToSceneRay;
    }
    tryToggleFromPixel(pixel) {
        if (!this.pixelToRay)
            return;
        const ray = this.pixelToRay(pixel);
        if (!ray)
            return;
        this.tryToggleFromRay(ray);
    }
    toggleByID(id) {
        if (!this.repo)
            return;
        if (!this.repo.editingID)
            return;
        const editingItem = this.repo.getForAppObject(this.repo.editingID);
        if (!editingItem)
            return;
        if (editingItem.targetIds.includes(id)) {
            editingItem.removeTargetID(id);
        }
        else {
            editingItem.addTargetID(id);
        }
    }
    tryToggleFromRay(ray) {
        if (!this.sceneRayPick)
            return;
        const pickedID = this.sceneRayPick(ray)?.appObjectID;
        if (!pickedID)
            return;
        this.toggleByID(pickedID);
    }
    constructor(appObject) {
        super(appObject, ToggleLabelDropTargetUC.type);
        this.appObjects.registerSingleton(this);
    }
}
//# sourceMappingURL=ToggleLabelDropTargetUC.js.map