import { _decorator, Component, Label, Node } from 'cc';
import { uiManager } from '../../manager/uiManager';
import { config } from '../../config';
import { userDataManager } from '../../manager/userDataManager';
import { select_area } from '../select_area/select_area';
import { area_item_data } from '../../data';
import { tools } from '../../tools';
const { ccclass, property } = _decorator;

@ccclass('home_top')
export class home_top extends Component {
    @property(Node) btn_region:Node = null
    @property(Node) lab_region:Node = null
    @property(Node) btn_gong_gao:Node = null
    @property(Node) btn_setting:Node = null
    @property(Node) lab_nickname:Node = null
    @property(Node) lab_car_pai:Node = null
    protected start(): void {
        uiManager.Instance().onButtonListen(this.btn_region,()=>{
            uiManager.Instance().showUi(config.UI.ui_select_area, null, (node:Node)=>{
                node.getComponent(select_area).initView(true, this.onSelectArea.bind(this))
            })
        })
        uiManager.Instance().onButtonListen(this.btn_gong_gao,()=>{
            uiManager.Instance().showUi(config.UI.ui_unLock_view)
        })
        uiManager.Instance().onButtonListen(this.btn_setting,()=>{
            uiManager.Instance().showUi(config.UI.ui_setting)
        })
    }
    public init(){
        this.lab_region.getComponent(Label).string = '北京市 - 北京市'
        let user_data = userDataManager.user_data
        this.lab_nickname.getComponent(Label).string = user_data.nickName
        this.lab_car_pai.getComponent(Label).string = user_data.license_code
    }

    private onSelectArea(obj:select_area, data:area_item_data) {
        tools.requestUserSetRegion(data.id, 2, (d)=>{
            obj.closeSelf()
        })
    }
}


