
import { _decorator } from 'cc';
import { ITEM_TYPE } from '../../../core/common/GameConst';
import BasePanel from '../../../core/component/BasePanel';
import Data from '../../../core/manager/Data';
import Utils from '../../../core/utils/Utils';
import platformSystem from 'db://assets/platform/platformSystem';
import { constants } from 'db://assets/data/constants';
import audioManager from 'db://assets/manager/audioManager';
const { ccclass, property } = _decorator;

@ccclass('BuyCoinLayer')
export class BuyCoinLayer extends BasePanel {
    start() {
        this.SetText("lbl_coin", Data.user.coin + "")
    }

    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_ad":
                this.GetGameObject("btn_close").active = false;
                platformSystem.platform.showRewardVideo((b) => {
                    if (b) {
                        Utils.flyAnim(ITEM_TYPE.Coin, this.GetNode("btn_ad"), this.GetNodeFromCanvas("coin-icon"), 5, 50, (b) => {
                            if (b) {
                                Data.user.coin += 100;
                                Data.save();
                                this.close();
                            }
                        });
                    }
                    else {
                        this.GetGameObject("btn_close").active = true;
                    }
                })
                break;
        }
    }
}