/**
 * 代码描述
 */

import { Audio } from "../../common/src/Audio";
import { GameDataCenter } from "../../common/src/GameDataCenter";
import { UIManager } from "../../common/src/UIManager";
import { Utils } from "../../common/src/Utils";


const { ccclass, property } = cc._decorator;

@ccclass
export class CoinStorePanel extends cc.Component {

    @property({ type: cc.Node, tooltip: '任务节点' })
    task: cc.Node = null;

    onEnable() {
        this.node.getChildByName('panel').getChildByName('closeButton').on('click', this.onClose, this);
        this.task.getChildByName('video').getChildByName('btn').on('click', this.onVideo, this);

        Utils.openPanel(this.node.getChildByName('panel'));
    }

    /**关闭 */
    private onClose(): void {
        Audio.playSoundByPath('coinStore:res/snd/click');
        UIManager.close('coinStore:CoinStorePanel', true);
    }

    /**看视频 */
    private onVideo(button): void {
        Audio.playSoundByPath('coinStore:res/snd/click');

        let num = +this.task.getChildByName('video').getChildByName('coin').getChildByName('num').getComponent(cc.Label).string;
        GameDataCenter.rewarded = [`4:${num}`];
        UIManager.open('rewarded:RewardedPanel');
    }
}