
import { _decorator,Node } from 'cc';
import BasePanel from '../../../core/component/BasePanel';
import Data from '../../../core/manager/Data';
import platformSystem from 'db://assets/platform/platformSystem';
import { constants } from 'db://assets/data/constants';
import audioManager from 'db://assets/manager/audioManager';
import settingData from 'db://assets/data/settingData';
import { auto } from 'db://assets/manager/autoBind';

const { ccclass, property } = _decorator;

@ccclass('SettingLayer')
export class SettingLayer extends BasePanel {
    @auto sound_on_icon: Node = null;
    @auto sound_off_icon: Node = null;
    @auto vibration_on_icon: Node = null;
    @auto vibration_off_icon: Node = null;

    start(){
        platformSystem.platform.showInterstitialAd();
        this.updateUI();
    }

    updateUI(){
        this.sound_on_icon.active = Data.user.soundVolume != 0;
        this.sound_off_icon.active = Data.user.soundVolume == 0;
        this.vibration_on_icon.active = Data.user.vibration != 0;
        this.vibration_off_icon.active = Data.user.vibration == 0;
    }

    onBtnClicked(event:any, customEventData:any) {
        audioManager.playOneShot(constants.audios.btnclick);
        var btnName = event.target.name;
        switch (btnName) {
            case "btn_close":
                this.close();
                break;
            case "btn_sound":
                settingData.changeStatus(1);
                Data.user.soundVolume = Data.user.soundVolume == 0?1:0;
                this.updateUI();
                break;
            case "btn_vibration":
                Data.user.vibration = Data.user.vibration == 0?1:0;
                this.updateUI();
                break;
        }
    }
}
