import { AppObjectUC, getSingletonComponent, } from "@vived/core";
import { ScenePixelPickUC, SceneRayPickUC } from "../../Babylon";
import { ToolRepository, ToolState } from "../../Tools";
import { HideUC } from "./HideUC";
export class TryHideWithPickUC extends AppObjectUC {
    static get(appObjects) {
        return getSingletonComponent(TryHideWithPickUC.type, appObjects);
    }
}
TryHideWithPickUC.type = "TryHideWithPickUC";
export function makeTryHideWithPickUC(appObject) {
    return new TryHideWithPickUCImp(appObject);
}
class TryHideWithPickUCImp extends TryHideWithPickUC {
    get rayPick() {
        return this.getCachedSingleton(SceneRayPickUC.type)
            ?.sceneRayPick;
    }
    get pixelPick() {
        return this.getCachedSingleton(ScenePixelPickUC.type)
            ?.scenePixelPick;
    }
    get toolRepo() {
        return this.getCachedSingleton(ToolRepository.type);
    }
    hideObjectByID(id) {
        const appObj = this.appObjects.get(id);
        if (!appObj) {
            return;
        }
        if (!appObj.hasComponent(HideUC.type)) {
            return;
        }
        HideUC.get(id, this.appObjects)?.hide();
    }
    constructor(appObject) {
        super(appObject, TryHideWithPickUC.type);
        this.allow = () => {
            const hideTool = this.toolRepo?.getTool("HIDE");
            if (hideTool?.state !== ToolState.ACTIVE) {
                return false;
            }
            return true;
        };
        this.tryPixelPick = (pixel) => {
            if (!this.allow())
                return;
            if (!this.pixelPick) {
                return;
            }
            const appObjectID = this.pixelPick(pixel)?.appObjectID;
            if (appObjectID) {
                this.hideObjectByID(appObjectID);
            }
        };
        this.tryRayPick = (pickRay) => {
            if (!this.allow())
                return;
            if (!this.rayPick) {
                return;
            }
            const appObjectID = this.rayPick(pickRay)?.appObjectID;
            if (appObjectID) {
                this.hideObjectByID(appObjectID);
            }
        };
        this.appObjects.registerSingleton(this);
    }
}
//# sourceMappingURL=TryHideWithPickUC.js.map