import { Debugger, ViverseApp } from './toolkit/core.mjs';
import { Billboard } from './toolkit/extension.mjs';
import { BillboardAxisAlignment, BillboardTargetType } from './toolkit/types.mjs';
import { Script } from "playcanvas";
/** @enum {string} */
const AxisAlignment = {
    None: 'none',
    X: 'x',
    Y: 'y',
    Z: 'z',
};
/** @enum {string} */
const TargetType = {
    ViverseCamera: 'viverseCamera',
    Entity: 'entity',
    Position: 'position',
};
export class ViverseBillboard extends Script {
    static scriptName = 'viverseBillboard';
    /**
     * The axis alignment of the billboard. Default is None (free on all axes).
     * @attribute
     * @title Axis Alignment
     * @type {AxisAlignment}
     */
    axisAlignment = AxisAlignment.None;
    /**
     * The target type of the billboard.
     * @attribute
     * @title Target Type
     * @type {TargetType}
     */
    targetType = TargetType.ViverseCamera;
    /**
     * The target entity of the billboard.
     * @attribute
     * @title Target Entity
     * @type {pc.Entity}
     * @visibleif { targetType === 'entity' }
     */
    targetEntity = null;
    /**
     * The target position of the billboard.
     * @attribute
     * @title Target Position
     * @type {pc.Vec3}
     * @visibleif { targetType === 'position' }
     */
    targetPosition = null;
    /**
     * The local rotation of the billboard.
     * @attribute
     * @title Rotation
     * @type {pc.Vec3}
     */
    rotation = null;
    _billboard = null;
    initialize() {
        const viverseApp = ViverseApp.getApplication();
        if (!viverseApp) {
            Debugger.error('[ViverseBillboard] ViverseApp is not initialized.');
            return;
        }
        this._billboard = new Billboard(viverseApp, this.entity, this.targetType, {
            axisAlignment: this.axisAlignment,
            targetEntity: this.targetEntity,
            targetPosition: this.targetPosition,
            rotateLocal: this.rotation,
        });
        this.on('destroy', this.destroy, this);
    }
    destroy() {
        this._billboard?.destroy();
    }
}
