var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { serializable } from "../engine/engine_serialization.js";
import { Behaviour } from "./Component.js";
import { EventList } from "./EventList.js";
import { EventType } from "./EventType.js";
class TriggerEvent {
    eventID;
    callback = new EventList();
}
__decorate([
    serializable()
], TriggerEvent.prototype, "eventID", void 0);
__decorate([
    serializable(EventList)
], TriggerEvent.prototype, "callback", void 0);
/**
 * The [EventTrigger](https://engine.needle.tools/docs/api/EventTrigger) component is used to trigger events when certain pointer events occur on the GameObject.
 * It implements the {@link IPointerEventHandler} interface and can be used to expose events to the user in the editor without writing code.
 *
 * @summary Triggers events on pointer interactions
 * @category Interactivity
 * @group Components
 */
export class EventTrigger extends Behaviour {
    /** A list of events that should be triggered when a pointer event occurs on the GameObject. */
    triggers = [];
    /** @internal */
    invoke(type) {
        if (!this.triggers)
            return;
        for (const trigger of this.triggers) {
            if (trigger.eventID === type) {
                trigger.callback?.invoke();
            }
        }
    }
    hasTrigger(type) {
        return this.triggers?.some(t => t.eventID === type) ?? false;
    }
    shouldChangeCursor() {
        return this.hasTrigger(EventType.PointerClick) || this.hasTrigger(EventType.PointerDown) || this.hasTrigger(EventType.PointerUp);
    }
    /** @internal */
    onPointerClick(_) {
        this.invoke(EventType.PointerClick);
    }
    /** @internal */
    onPointerEnter(_) {
        if (this.shouldChangeCursor()) {
            this.context.input.setCursor("pointer");
        }
        this.invoke(EventType.PointerEnter);
    }
    /** @internal */
    onPointerExit(_) {
        if (this.shouldChangeCursor()) {
            this.context.input.unsetCursor("pointer");
        }
        this.invoke(EventType.PointerExit);
    }
    /** @internal */
    onPointerDown(_) {
        this.invoke(EventType.PointerDown);
    }
    /** @internal */
    onPointerUp(_) {
        this.invoke(EventType.PointerUp);
    }
}
__decorate([
    serializable(TriggerEvent)
], EventTrigger.prototype, "triggers", void 0);
//# sourceMappingURL=EventTrigger.js.map