import { _decorator, Component, Label, Node } from 'cc';
import { attributes_data, event_item, event_start_event_item } from '../../../data/data';
import { Attributes } from '../Attributes';
import { tools } from '../../tools';
import { ClientEvent } from '../../clientEvent';
import { config } from '../../config';
const { ccclass, property } = _decorator;

@ccclass('event_start_event')
export class event_start_event extends Component {
    private m_data:event_start_event_item = null;
    @property(Node) btn_select_ui:Node = null;
    @property(Node) lab_name:Node = null;
    public initView(data:event_start_event_item){
        this.m_data = data;
        this.btn_select_ui.on(Node.EventType.TOUCH_END,()=>{
            let list = Attributes.Singleton.getEventList()
            tools.show_select_evele_list(list,(data:event_item)=>{
                this.m_data.binding_event_id = data.event_id;
                this.updateStatus()
            })
          
        })
        this.updateStatus()
    }
    updateStatus(){
        if(this.m_data.binding_event_id!=-1){
            let data = Attributes.Singleton.getEventItemById(this.m_data.binding_event_id)
            if(data==null){
                this.m_data.binding_event_id = -1;
            }
        }

       this.lab_name.getComponent(Label).string = this.m_data.binding_event_id==-1?"选择一个开始的事件": `开始的事件的id:${this.m_data.binding_event_id}`
    }
}


