"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MouseHoverOnAppObject = void 0;
const core_1 = require("@vived/core");
const Babylon_1 = require("../../Babylon");
const MouseInput_1 = require("../../MouseInput");
const ZSpaceEntity_1 = require("../../zSpace/Entities/ZSpaceEntity");
const HoverAppObjectUC_1 = require("../UC/HoverAppObjectUC");
class MouseHoverOnAppObject extends core_1.AppObjectController {
    constructor(appObject) {
        super(appObject, MouseHoverOnAppObject.type);
        this.zSpaceEntity = undefined;
        this.allow = (e) => {
            return true;
        };
        this.onMove = (e) => {
            if (!this.hoverUC)
                return;
            if (this.zSpaceEntity && this.zSpaceEntity.emulate)
                return;
            if (!this.allow(e))
                return;
            const ray = (0, Babylon_1.pixelToSceneRay)(e.position, this.appObjects);
            this.hoverUC.tryHoverAppObject(ray);
        };
        this.zSpaceEntity = ZSpaceEntity_1.ZSpaceEntity.get(this.appObjects);
        this.hoverUC = appObject.getComponent(HoverAppObjectUC_1.HoverAppObjectUC.type);
        if (!this.hoverUC) {
            console.warn("MouseHover has been added to an App Object that does not have a HoverAppObjectUC. Add an HoverAppObjectUC before adding the Controller");
            return;
        }
        const mouseInput = MouseInput_1.MouseInputEntity.get(this.appObjects);
        if (mouseInput) {
            mouseInput.registerController(this);
        }
        else {
            this.warn("Unable to find MouseInputEntity");
        }
    }
}
exports.MouseHoverOnAppObject = MouseHoverOnAppObject;
MouseHoverOnAppObject.type = "MouseHoverOnAppObject";
//# sourceMappingURL=MouseHoverOnAppObject.js.map