import { sys } from "cc";
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
import { GameEvent } from "../../game/common/config/GameEvent";

// LaunchManager.ts
export class LaunchManager {


    private static instance: LaunchManager;
    private _fromSide: boolean = false;
    /** 
     * 是否从侧边栏进入 
    */
    get fromSide(): boolean {
        return this._fromSide;
    }
    /** 
     * 设置侧边开关值
     * @param value     开关值
     */
    set fromSide(value: boolean) {
        this._fromSide = value;

    }

    private constructor() {}

    // 获取LaunchManager的单例对象
    public static getInstance(): LaunchManager {
        if (!LaunchManager.instance) {
            LaunchManager.instance = new LaunchManager();
        }
        return LaunchManager.instance;
    }

    // 生命周期
    onShow() {
        if (sys.platform === sys.Platform.BYTEDANCE_MINI_GAME) {
            tt.onShow((res) => {
                //判断用户是否是从侧边栏进来的
                this.fromSide = (res.launch_from == 'homepage' && res.location == 'sidebar_card')
                if(this.fromSide)oops.message.dispatchEvent(GameEvent.SideBarEnter)
            });
        } else {
            console.log("Side reward called in unsupported platform");
        }
    }

}

