import { oops } from "../../../../../extensions/oops-plugin-framework/assets/core/Oops";
import { ecs } from "../../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
import { VM } from "../../../../../extensions/oops-plugin-framework/assets/libs/model-view/ViewModel";
import { VibrationManager } from "../../../platform/vibration/VibrationManager";





@ecs.register('AccountModelSetting')
export class AccountModelSettingComp extends ecs.Comp {

    /** 提供 VM 组件使用的数据 */
    vm: AccountSettingVM = new AccountSettingVM();

    vmAdd() {
        VM.add(this.vm, "AccountSetting");
    }

    get musicOn(): boolean {
        return this.vm.musicOn
    }
    set musicOn(val: boolean) {
        this.vm.musicOn = val
        oops.audio.switchMusic = val
        if (val) {
            // oops.audio.stopAll()
            // oops.audio.playerMusicLoop("common/audio/bgm");
            oops.audio.resumeAll()
        }else{
            oops.audio.pauseAll()
        }
        oops.storage.set("musicOn", val)
        
    }

    get effectOn(): boolean {
        return this.vm.effectOn
    }
    set effectOn(val: boolean) {
        this.vm.effectOn = val
        oops.audio.switchEffect = val
        oops.storage.set("effectOn", val)
    }

    get vibrationOn(): boolean {
        return this.vm.vibrationOn
    }
    set vibrationOn(val: boolean) {
        this.vm.vibrationOn = val
        VibrationManager.getInstance().switchVibration = val
        oops.storage.set("vibrationOn", val)
    }

    vmRemove() {
        this.vm.reset();
        VM.remove("AccountSetting");
    }

    reset() {
        this.vmRemove();
    }
}

class AccountSettingVM {
    /** 声音 */
    musicOn: boolean = true;
    /** 特效 */
    effectOn: boolean = true;
    /** 震动 */
    vibrationOn: boolean = true;

    reset() {
        this.musicOn = true;
        this.effectOn = true;
        this.vibrationOn = true;
    }
}