import type { Context } from '../engine/engine_context.js';
import { serializable } from '../engine/engine_serialization.js';
import { DeviceUtilities } from '../engine/engine_utils.js';
import { Behaviour } from './Component.js';

/** 
 * Exposes options to customize the built-in Needle Menu.  
 * From code, you can access the menu via {@link Context.menu}. 
 * @category User Interface
 * @group Components
 **/
export class NeedleMenu extends Behaviour {

    @serializable()
    position: "top" | "bottom" = "bottom";

    /** Show the Needle logo in the menu (requires PRO license) */
    @serializable()
    showNeedleLogo: boolean = true;

    /** When enabled the menu will also be visible in VR/AR when you look up 
     * @default undefined
    */
    @serializable()
    showSpatialMenu?: boolean;

    /** When enabled a button to enter fullscreen will be added to the menu 
     * @default undefined
    */
    @serializable()
    createFullscreenButton?: boolean;
    /** When enabled a button to mute the application will be added to the menu 
     * @default undefined
    */
    @serializable()
    createMuteButton?: boolean;

    /**
     * When enabled a button to show a QR code will be added to the menu.
     * @default undefined
     */
    @serializable()
    createQRCodeButton?: boolean;

    /** @hidden */
    onEnable() {
        this.applyOptions();
    }

    /** applies the options to `this.context.menu` */
    applyOptions() {
        this.context.menu.setPosition(this.position);
        this.context.menu.showNeedleLogo(this.showNeedleLogo);
        if (this.createFullscreenButton === true)
            this.context.menu.showFullscreenOption(true);
        if (this.createMuteButton === true)
            this.context.menu.showAudioPlaybackOption(true);
        if (this.showSpatialMenu === true)
            this.context.menu.showSpatialMenu(this.showSpatialMenu);
        if (this.createQRCodeButton === true) {
            if (!DeviceUtilities.isMobileDevice()) {
                this.context.menu.showQRCodeButton(true);
            }
        }
    }

}