
import { _decorator } from 'cc';

import BasePanel from '../core/component/BasePanel';
import Data from '../core/manager/Data';
import Utils from '../core/utils/Utils';
import { audioMgr } from '../core/manager/AudioManager';
import platformSystem from '../platform/platformSystem';
import { GameConst, ITEM_TYPE } from '../core/common/GameConst';
import { GameNode } from '../game/GameNode';
import { Main } from '../game/Main';
const { ccclass, property } = _decorator;

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

    onBtnClicked(event: any, customEventData: any) {
        audioMgr.playOneShot(GameConst.audios.btnclick);
        var btnName = event.target.name;
        switch (btnName) {
            case "btn_close":
                this.close();
                break;
            case "btn_ad":
                platformSystem.platform.showRewardVideo((f) => {
                    if (f) {
                        let coinIcon:any = Main.I._HallUI.GetGameObject("coin-icon");
                        Utils.flyAnim(ITEM_TYPE.Coin, this.GetNode("btn_ad"), coinIcon, 5, 50, (b) => {
                            if (b) {
                                Data.user.coin += 100;
                                Data.save();
                                this.close();
                            }
                        });
                    }
                })
                break;
        }
    }
}