import { _decorator, Component, Node, LabelComponent } from 'cc';
import { NoticeManager } from '../../../engines/notices/NoticeManager';
import StringUtils from '../../../engines/utils/StringUtils';
import { PlatformManager } from '../../../Platform/PlatformManager';
import { branchIdType } from '../../../Platform/WeChat/branchIdType';
import { WeChatPlatform } from '../../../Platform/WeChat/WeChatPlatform';
import { GameModel } from '../../models/GameModel';
const { ccclass, property } = _decorator;

@ccclass('ExchangeItemRenderScript')
export class ExchangeItemRenderScript extends Component {

    @property({
        type: LabelComponent
    })
    timeLabel: LabelComponent = null;

    @property({
        type: LabelComponent
    })
    timeLabel1: LabelComponent = null;

    @property({
        type: LabelComponent
    })
    goldLabel: LabelComponent = null;

    @property({
        type: LabelComponent
    })
    diamondLabel: LabelComponent = null;

    private data: any;

    UpdateItemRender(data: any): void {
        this.data = data;
        let time: number = data.time / 60 / 60;
        this.timeLabel.string = time + "小时枪械收益";
        this.timeLabel1.string = "立即获得" + time + "小时枪械收益！";
        this.goldLabel.string = StringUtils.numberUtilsEn(GameModel.single.fullEarnings * data.time);
        this.diamondLabel.string = StringUtils.numberUtilsEn(data.useDiamond, 0);
    }

    /**
     * 购买
     */
    BuyButtonClickHandler(): void {
        if (GameModel.single.diamond < this.data.useDiamond) {
            NoticeManager.ShowPrompt("钻石不足！");
        } else {
            GameModel.single.diamond -= this.data.useDiamond;
            let weChat = PlatformManager.impl as WeChatPlatform;
            if (weChat instanceof WeChatPlatform) {
                weChat.branchAnalytics(branchIdType.GoldExchange, String(this.data.useDiamond))
            }
        }
    }

    start() {
        // Your initialization goes here.
    }

    // update (deltaTime: number) {
    //     // Your update function goes here.
    // }
}
