import { _decorator, Component, Node, Sprite, SpriteFrame, Animation } from 'cc';
import { tools } from '../../tools';
const { ccclass, property } = _decorator;

@ccclass('home_honor')
export class home_honor extends Component {
    @property(Node) img_text:Node = null
    @property(Node) img_light:Node = null

    @property(SpriteFrame) sf_country_text:SpriteFrame = null
    @property(SpriteFrame) sf_country_light:SpriteFrame = null
    @property(SpriteFrame) sf_province_text:SpriteFrame = null
    @property(SpriteFrame) sf_province_light:SpriteFrame = null
    @property(SpriteFrame) sf_city_text:SpriteFrame = null
    @property(SpriteFrame) sf_city_light:SpriteFrame = null

    initView() {
        let rank_data = tools.mine_rank_data
        if(rank_data.nationwide_badge_status==undefined||rank_data.nationwide_badge_status==null) {
            rank_data.nationwide_badge_status = 0
        }
        if(rank_data.province_badge_status==undefined||rank_data.province_badge_status==null) {
            rank_data.province_badge_status = 0
        }
        if(rank_data.city_badge_status==undefined||rank_data.city_badge_status==null) {
            rank_data.city_badge_status = 0
        }
        if(rank_data.nationwide_badge_status==0&&rank_data.province_badge_status==0&&rank_data.city_badge_status==0) {
            this.node.active = false
            this.img_light.getComponent(Animation).stop()
            return
        } 

        this.node.active = true
        this.img_light.getComponent(Animation).play()

        if(rank_data.nationwide_badge_status==1) {
            this.img_text.getComponent(Sprite).spriteFrame = this.sf_country_text
            this.img_light.getComponent(Sprite).spriteFrame = this.sf_country_light
            return
        } 
        if(rank_data.province_badge_status==1) {
            this.img_text.getComponent(Sprite).spriteFrame = this.sf_province_text
            this.img_light.getComponent(Sprite).spriteFrame = this.sf_province_light
            return
        }
        if(rank_data.city_badge_status==1) {
            this.img_text.getComponent(Sprite).spriteFrame = this.sf_city_text
            this.img_light.getComponent(Sprite).spriteFrame = this.sf_city_light
            return
        }
    }
}

