"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.HoverLabelMouse = void 0;
exports.makeHoverLabelMouse = makeHoverLabelMouse;
const TryShowHoverLabel_1 = require("../UseCases/TryShowHoverLabel");
const HoverLabelEntity_1 = require("../Entities/HoverLabelEntity");
const core_1 = require("@vived/core");
const MouseInput_1 = require("../../MouseInput");
class HoverLabelMouse extends core_1.AppObjectController {
}
exports.HoverLabelMouse = HoverLabelMouse;
HoverLabelMouse.type = "Mouse_HoverLabel_Controller";
function makeHoverLabelMouse(appObject) {
    return new HoverLabelMouseImp(appObject);
}
class HoverLabelMouseImp extends HoverLabelMouse {
    constructor(appObject) {
        super(appObject, HoverLabelMouse.type);
        this.hoverLabelDelay = 500;
        this.allow = (e) => {
            return true;
        };
        this.onMove = (e) => {
            if (!this.allow(e))
                return;
            if (!this.hoverLabelEntity)
                return;
            if (!this.tryShowHoverLabel)
                return;
            this.hoverLabelEntity.hideHoverLabel();
            if (this.currentTimeout) {
                clearTimeout(this.currentTimeout);
            }
            this.currentTimeout = setTimeout(() => {
                this.tryShowHoverLabel?.tryShowScreenHoverLabel(e.position);
                this.currentTimeout = undefined;
            }, this.hoverLabelDelay);
        };
        this.hoverLabelEntity = this.appObject.getComponent(HoverLabelEntity_1.HoverLabelEntity.type);
        if (!this.hoverLabelEntity) {
            this.warn("Serializer has been added to an App Object that does not have a HoverLabelEntity. Add the Entity first");
            return;
        }
        this.tryShowHoverLabel = TryShowHoverLabel_1.TryShowHoverLabel.get(this.appObjects);
        if (!this.tryShowHoverLabel) {
            this.warn("Unable to find TryShowHoverLabel UC");
            return;
        }
        const mouseInput = MouseInput_1.MouseInputEntity.get(this.appObjects);
        if (mouseInput) {
            mouseInput.registerController(this);
        }
        else {
            this.warn("Unable to find MouseInputEntity");
        }
    }
}
//# sourceMappingURL=HoverLabelMouse.js.map