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

@ccclass('task_dai_dao_ju')
export class task_dai_dao_ju extends Component {
    @property(Node) btn_setting:Node = null;
    @property(Node) eidt_time:Node = null;
    @property(Node) btn_binding_count_time_widget:Node = null;
    @property(Node) lab_binding_count_time_widget:Node = null;
    @property(Node) btn_binding_finish_event:Node = null;
    @property(Node) lab_binding_finish_event:Node = null;
    private m_data:guo_ju_qing_dai_dao_ju = null;
    public updateView(data:guo_ju_qing_dai_dao_ju){
        this.m_data = data;
        this.btn_setting.off(Node.EventType.TOUCH_END);
        this.btn_setting.on(Node.EventType.TOUCH_END,()=>{
            tools.select_task_dai_dao_ju(this.m_data)
        })
        this.btn_setting.off(EditBox.EventType.EDITING_DID_ENDED);
        this.eidt_time.on(EditBox.EventType.EDITING_DID_ENDED,()=>{
            this.m_data.add_time_number = parseInt(this.eidt_time.getComponent(EditBox).string)
            this.updateStatus()
        })

        this.btn_binding_finish_event.on(Node.EventType.TOUCH_END,()=>{
            let list = Attributes.Singleton.getEventList()
            tools.show_select_evele_list(list,(data:event_item)=>{
                this.m_data.finish_event_id = data.event_id;
                this.updateStatus()
            })
        })

        this.btn_binding_count_time_widget.on(Node.EventType.TOUCH_END,()=>{
            let list =  Attributes.Singleton.get_cur_scene_widget_by_type(config.Widget_Type_List.COUNT_DOWN)
            if(list.length<=0){
                return tools.showToast("当前场景没有倒计时控件！")
            }
            tools.show_select_widget_list(list,(item:widget_item_data)=>{
                this.m_data.binding_count_time_widget = item.att.id;
                this.updateStatus()
            },this.m_data.binding_count_time_widget)
        })
        this.updateStatus()
    }

    updateStatus(){
        if(this.m_data.finish_event_id!=-1){
            this.lab_binding_finish_event.getComponent(Label).string = "完成事件id:"+this.m_data.finish_event_id;
        }
        if(this.m_data.binding_count_time_widget!=-1){
            this.lab_binding_count_time_widget.getComponent(Label).string = "倒计时控件id:"+this.m_data.binding_count_time_widget;
        }
        this.eidt_time.getComponent(EditBox).string = this.m_data.add_time_number+"";
    }
}


 