"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TryHideWithPickUC = void 0;
exports.makeTryHideWithPickUC = makeTryHideWithPickUC;
const core_1 = require("@vived/core");
const Babylon_1 = require("../../Babylon");
const Tools_1 = require("../../Tools");
const HideUC_1 = require("./HideUC");
class TryHideWithPickUC extends core_1.AppObjectUC {
    static get(appObjects) {
        return (0, core_1.getSingletonComponent)(TryHideWithPickUC.type, appObjects);
    }
}
exports.TryHideWithPickUC = TryHideWithPickUC;
TryHideWithPickUC.type = "TryHideWithPickUC";
function makeTryHideWithPickUC(appObject) {
    return new TryHideWithPickUCImp(appObject);
}
class TryHideWithPickUCImp extends TryHideWithPickUC {
    get rayPick() {
        return this.getCachedSingleton(Babylon_1.SceneRayPickUC.type)
            ?.sceneRayPick;
    }
    get pixelPick() {
        return this.getCachedSingleton(Babylon_1.ScenePixelPickUC.type)
            ?.scenePixelPick;
    }
    get toolRepo() {
        return this.getCachedSingleton(Tools_1.ToolRepository.type);
    }
    hideObjectByID(id) {
        const appObj = this.appObjects.get(id);
        if (!appObj) {
            return;
        }
        if (!appObj.hasComponent(HideUC_1.HideUC.type)) {
            return;
        }
        HideUC_1.HideUC.get(id, this.appObjects)?.hide();
    }
    constructor(appObject) {
        super(appObject, TryHideWithPickUC.type);
        this.allow = () => {
            const hideTool = this.toolRepo?.getTool("HIDE");
            if (hideTool?.state !== Tools_1.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