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 { AnimationClip } from "three";
import { AnimationUtils } from "../../engine/engine_animation.js";
import { serializable } from "../../engine/engine_serialization_decorator.js";
import { registerType } from "../../engine/engine_typestore.js";
import { Animation } from "../Animation.js";
import { Behaviour } from "../Component.js";
/**
 * Plays a hover animation on the object this component was added to when the mouse pointer (or touch) is over the object or any of it's children.
 *
 * By default, a simple scale-up animation is used. You can customize the hover and idle animations by providing your own animation clips.
 *
 * @summary Hover Animation on Pointer Enter/Exit
 * @category Web
 * @group Components
 */
let HoverAnimation = class HoverAnimation extends Behaviour {
    /**
     * Default hover animation type if no custom clip is provided.
     * **Node**: This is only used if no custom hover animation clip is provided.
     * @default "linear"
     */
    type = "linear";
    /**
     * Duration of the hover animation in seconds.
     * **Node**: This is only used if no custom hover animation clip is provided.
     * @default 0.1
     */
    duration = 0.1;
    /**
     * Scale factor to apply when hovering.
     * **Node**: This is only used if no custom hover animation clip is provided.
     * @default 1.1
     */
    scaleFactor = 1.1;
    /**
     * Animation clip to play when hovering. If null, a default scale-up animation is used.
     */
    hovered = null;
    /**
     * Animation clip to play when not hovering. If null, an empty clip is used.
     */
    idle = null;
    animation = null;
    start() {
        if (!this.idle)
            this.idle = AnimationUtils.emptyClip();
        if (!this.hovered || !(this.hovered instanceof AnimationClip)) {
            this.hovered = AnimationUtils.createScaleClip({
                type: "linear",
                duration: this.duration || 0.1,
                scale: this.gameObject.scale,
                scaleFactor: this.scaleFactor || 1.1,
            });
        }
        this.animation ??= this.gameObject.addComponent(Animation);
        this.animation.playAutomatically = false;
        this.playIdle();
    }
    onEnable() {
        if (this.animation)
            this.animation.enabled = true;
        this.playIdle();
    }
    onDisable() {
        if (this.animation)
            this.animation.enabled = false;
        this.playIdle();
    }
    onPointerEnter() {
        this.playHover();
    }
    onPointerExit() {
        this.playIdle();
    }
    playIdle() {
        if (this.idle)
            this.animation?.play(this.idle, { exclusive: true, fadeDuration: .1, loop: true });
    }
    playHover() {
        if (this.hovered)
            this.animation?.play(this.hovered, { exclusive: true, fadeDuration: .1, loop: false, clampWhenFinished: true });
    }
};
__decorate([
    serializable()
], HoverAnimation.prototype, "type", void 0);
__decorate([
    serializable()
], HoverAnimation.prototype, "duration", void 0);
__decorate([
    serializable()
], HoverAnimation.prototype, "scaleFactor", void 0);
__decorate([
    serializable(AnimationClip)
], HoverAnimation.prototype, "hovered", void 0);
__decorate([
    serializable(AnimationClip)
], HoverAnimation.prototype, "idle", void 0);
HoverAnimation = __decorate([
    registerType
], HoverAnimation);
export { HoverAnimation };
//# sourceMappingURL=HoverAnimation.js.map