import { _decorator, Component, Label, Node, Sprite } from 'cc';
import { uiManager } from '../../manager/uiManager';
import { config } from '../../config';
import { userDataManager } from '../../manager/userDataManager';
import { home_guangbo } from './home_guangbo';
import { tools } from '../../tools';
import { GameManager } from '../../GameManager';
import { gameSocket } from '../../socket/gameSocket';
const { ccclass, property } = _decorator;

@ccclass('home_top')
export class home_top extends Component {
    @property(Node) lab_region:Node = null
    @property(Node) img_avatar:Node = null
    @property(Node) lab_nickname:Node = null
    @property(Node) btn_car_lib:Node = null
    @property(Node) lab_car_pai:Node = null
    @property(Node) btn_gong_gao:Node = null
    @property(Node) btn_setting:Node = null
    @property(Node) btn_feedback:Node = null
    @property(Node) guangbo:Node = null
    protected start(): void {
        uiManager.Instance().onButtonListen(this.btn_gong_gao,()=>{
            uiManager.Instance().showUi(config.UI.ui_announcement)
        })
        uiManager.Instance().onButtonListen(this.btn_setting,()=>{
            uiManager.Instance().showUi(config.UI.ui_setting)
        })
        uiManager.Instance().onButtonListen(this.btn_car_lib, ()=>{
            this.node.parent.active = false
            uiManager.Instance().showUi(config.UI.car_lib, null, ()=>{
                this.node.parent.active = true
            })
        })
        uiManager.Instance().onButtonListen(this.btn_feedback, ()=>{
            uiManager.Instance().showUi(config.UI.ui_feedback)
        })
    }
    public init(){
        let user_data = userDataManager.user_data
        this.lab_region.getComponent(Label).string = user_data.province_name + ' - ' + user_data.city_name
        tools.loadRemoteImg(user_data.avatarUrl, (r)=>{
            this.img_avatar.getComponent(Sprite).spriteFrame = r.sf
        })
        this.lab_nickname.getComponent(Label).string = user_data.nickName
        this.lab_car_pai.getComponent(Label).string = user_data.license_code
        this.requestGuangboData()
    }

    public requestGuangboData() {
        GameManager.requestGuangbo((d_content)=>{
            this.reloadGuangboData(d_content)
        })
    }

    public reloadGuangboData(d_content) {
        this.guangbo.getComponent(home_guangbo).init(d_content)
    }
    
}


