import { _decorator, Component, EditBox, Label, Node } from 'cc';
import { tools } from '../../tools';
import { Attributes } from '../Attributes';
import { event_item, event_item_delay_exe_event, event_start_event_item } from '../../../data/data';
const { ccclass, property } = _decorator;

@ccclass('event_delay_exe_event')
export class event_delay_exe_event extends Component {
    private m_data:event_item_delay_exe_event = null;
    @property(Node) btn_select_ui:Node = null;
    @property(Node) lab_name:Node = null;
    @property(EditBox) edit_time:EditBox =null; 
    public initView(data:event_item_delay_exe_event){
        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.edit_time.node.on('editing-did-ended',()=>{
            this.m_data.delay_time = parseFloat(this.edit_time.string)
        })
        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;
            }
            if(this.m_data.delay_time!=undefined){
                this.edit_time.string = this.m_data.delay_time.toString()
            }
        }
      
       this.lab_name.getComponent(Label).string = this.m_data.binding_event_id==-1?"选择一个事件": `事件的id:${this.m_data.binding_event_id}`
    }
}


