"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ToggleLabelDropTargetUC = void 0;
exports.makeToggleLabelDropTargetUC = makeToggleLabelDropTargetUC;
const core_1 = require("@vived/core");
const UC_1 = require("../../Babylon/UC");
const LabelDropRepo_1 = require("../Entities/LabelDropRepo");
class ToggleLabelDropTargetUC extends core_1.AppObjectUC {
    static get(appObjects) {
        return (0, core_1.getSingletonComponent)(ToggleLabelDropTargetUC.type, appObjects);
    }
}
exports.ToggleLabelDropTargetUC = ToggleLabelDropTargetUC;
ToggleLabelDropTargetUC.type = "ToggleLabelDropTargetUC";
function makeToggleLabelDropTargetUC(appObject) {
    return new ToggleLabelDropTargetUCImp(appObject);
}
class ToggleLabelDropTargetUCImp extends ToggleLabelDropTargetUC {
    get repo() {
        return this.getCachedSingleton(LabelDropRepo_1.LabelDropRepo.type);
    }
    get sceneRayPick() {
        return this.getCachedSingleton(UC_1.SceneRayPickUC.type)
            ?.sceneRayPick;
    }
    get pixelToRay() {
        return this.getCachedSingleton(UC_1.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