import { _decorator, Component, Node } from 'cc';
import { TB, TbGEnum } from '../../config/data/schema';
import JNScrollViewItem from '../../../../extensions/ngame/assets/ngame/util/components/scrollview/JNScrollViewItem';
import { TD } from '../../App';
import { Label } from 'cc';
import JNScrollView from '../../../../extensions/ngame/assets/ngame/util/components/scrollview/JNScrollView';
import GiftData from '../../data/GiftData';
import NumberTools from '../../tools/NumberTools';
const { ccclass, property } = _decorator;

@ccclass('ShopGiftItem')
export class ShopGiftItem extends JNScrollViewItem<TB.TbGShop> {

    @property(Label)
    giftName:Label;     //礼包名称

    @property(Label)
    giftLimit:Label;    //限购

    @property(Label)
    giftPrice:Label;    //价格

    @property(JNScrollView)
    views:JNScrollView;     //礼包列表

    gift: TB.TbGGift;

    onInit(data: TB.TbGShop): void {
        
        this.gift = TD.TbGGift.get(data.giftId);

        this.giftName.string = this.data.tig;

        if(this.gift.limit == TbGEnum.TGiftLimit.Unlimited)
            this.giftLimit.string = "( 无限 )";
        if(this.gift.limit == TbGEnum.TGiftLimit.DayLimit)
            this.giftLimit.string = `每天( ${GiftData.getIns().getGiftDayRecordCount(this.gift.id)}/${this.gift.limitValue} )`;
        if(this.gift.limit == TbGEnum.TGiftLimit.Limit)
            this.giftLimit.string = `限制( ${GiftData.getIns().getGiftRecordCount(this.gift.id)}/${this.gift.limitValue} )`;

        this.giftPrice.string = `${NumberTools.NumberStr(this.gift.exchanges[0].value)} ${TD.TbGResource.get(this.gift.exchanges[0].id).name}`;
        this.views.refreshData(this.gift.rewards);


    }    

    //点击购买礼包
    async onClickBuy(){
        await GiftData.getIns().buy(this.gift.id)
    }

}


