import { Script, Entity, Vec3 } from "playcanvas";
import { Debugger, ViverseApp } from './toolkit/core.mjs';
import { SitInteraction } from './toolkit/extension.mjs';
export class ViverseSit extends Script {
    static scriptName = 'viverseSit';
    /**
     * Radius (in meters) representing the size of the seat.
     * @attribute
     * @title Seat Radius
     * @type {number}
     * @range [0, 20]
     * @precision 2
     * @step 0.01
     */
    seatRadius = 0.5;
    /**
     * Whether to make the player stand up when local player movement input is detected.
     * @attribute
     * @title Stand When Moving
     * @type {boolean}
     */
    standUpOnMoveInput = true;
    /**
     * Whether to show interaction hint icon above this seat.
     * Player can take a seat by clicking on it.
     * @attribute
     * @title Show Hint Icon
     * @type {boolean}
     */
    useHintIcon = true;
    /**
     * Radius (in meters) for showing the interactive hint icon.
     * Please ensure this radius is larger than the outer radius.
     * @attribute
     * @title Hint Inner Range
     * @type {number}
     * @range [0, 100]
     * @precision 2
     * @step 0.01
     * @visibleif {useHintIcon}
     */
    hintInnerRadius = 1;
    /**
     * Radius (in meters) for showing non-interactive hint icon as indicator.
     * @attribute
     * @title Hint Outer Range
     * @type {number}
     * @range [0, 100]
     * @precision 2
     * @step 0.01
     * @visibleif {useHintIcon}
     */
    hintOuterRadius = 2;
    /**
     * Height of the cylindrical interaction range detection.
     * @attribute
     * @title Range Height
     * @type {number}
     * @range [0, 20]
     * @precision 2
     * @step 0.01
     * @visibleif {useHintIcon}
     */
    rangeHeight = 0.1;
    /**
     * Offset of the cylindrical interaction range detection.
     * @attribute
     * @title Range Offset
     * @type {pc.Vec3}
     * @visibleif {useHintIcon}
     */
    rangeOffset = new Vec3(0, 0, 0);
    /**
     * Set custom exit point where player should stand after leaving this seat.
     * If not provided, the player will stand in front of the seat by default.
     * @attribute
     * @title Use Exit Point
     * @type {boolean}
     */
    useExitPoint = false;
    /**
     * Optional exit point where the player should stand after leaving this seat.
     * If not provided, the player will stand in front of the seat by default.
     * @attribute
     * @title Exit Point
     * @type {Entity}
     * @visibleif { useExitPoint }
     */
    exitPoint;
    _sit = null;
    initialize() {
        const viverseApp = ViverseApp.getApplication();
        if (!viverseApp) {
            Debugger.error('[ViverseSit] ViverseApp is not initialized.');
            return;
        }
        const config = {
            name: `${this.entity.name}_${crypto.randomUUID()}`,
            standUpOnMoveInput: this.standUpOnMoveInput,
            useHintIcon: this.useHintIcon,
            seatRadius: this.seatRadius,
            rangeRadius: {
                inner: this.hintInnerRadius,
                outer: this.hintOuterRadius,
            },
            rangeHeight: this.rangeHeight,
            rangeOffset: this.rangeOffset,
            ...(this.useExitPoint && {
                exitPoint: this.exitPoint,
            }),
        };
        this._sit = new SitInteraction(viverseApp, this.entity, config);
        this.on('destroy', this.destroy, this);
    }
    /**
     * Called every frame while the script is enabled.
     * @param {number} dt - Delta time since last frame.
     */
    update(_dt) { }
    destroy() {
        if (this._sit) {
            this._sit.destroy();
            this._sit = null;
        }
    }
}
// HACK: This block is purely for ensuring type-only imports are preserved in the build output.
// The attribute-parser needs these imports to correctly parse the script attributes.
// This code will never run and will be tree-shaken from the final application bundle.
if (
// eslint-disable-next-line no-constant-condition
false) {
    Debugger.log(Script, Entity);
}
