import { _decorator, Component, Node, find, SpriteFrame, SpriteComponent, LabelComponent, loader, assert } from 'cc';
import GameConfigManager from '../../models/GameConfigManager';
import { GameModel } from '../../models/GameModel';
const { ccclass, property } = _decorator;

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

    private config:any;
    UpdateItemRender(data:any):void{
        this.config=data;
        let state:number=GameModel.single.GetSignAwardByDay(this.config.id);

        let icon:SpriteComponent=find("Icon",this.node).getComponent(SpriteComponent);
        let num:LabelComponent=find("Num",this.node).getComponent(LabelComponent);

        let dIcon:Node=find("diamondIcon",this.node);
        let gIcon:Node=find("goldIcon",this.node);

        dIcon.active=false;
        gIcon.active=false;
        //0.金币 1.钻石 2.枪 3.栅栏
        switch (this.config.type) {
            case 0:
                gIcon.active=true;
                icon.node.active=false;
                num.string=this.config.number;
                break;
            case 1:
                dIcon.active=true;
                icon.node.active=false;
                num.string=this.config.number;
                break;
            case 2:
                let weaponConfig:any=GameConfigManager.GetWeaponConfig(this.config.number);
                loader.loadRes(weaponConfig.icon+"/spriteFrame",SpriteFrame,(err,res:SpriteFrame)=>{
                    if(err!=null){
                        console.log("加载图标出错！");
                    }
                    icon.spriteFrame=res;
                });
                num.string=weaponConfig.name;
                break;
            case 3:
                let fenceConfig:any=GameConfigManager.GetFenceConfig(this.config.number);
                loader.loadRes(fenceConfig.icon+"/spriteFrame",SpriteFrame,(err,res:SpriteFrame)=>{
                    if(err!=null){
                        console.log("加载图标出错！");
                    }
                    icon.spriteFrame=res;
                });
                num.string=fenceConfig.name;
                break;
            default:
                throw new Error("7日登录奖励配置类型错误:"+this.config.type)
        }
        
        let ImgYiLingQu:Node=find("ImgYiLingQu",this.node);
        let stateLabel:Node=find("stateLabel",this.node);
        stateLabel.active=false;
        //可领取
        if(this.config.id<=GameModel.single.signDay){
            //未领取
            if(state==0){
                ImgYiLingQu.active=false;
            }else{//已领取
                ImgYiLingQu.active=true;
                stateLabel.active=true;
            }
        }else{//不可领取
            ImgYiLingQu.active=true;
        }
    }

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

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