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

@ccclass('select_task_da_guai_item')
export class select_task_da_guai_item extends Component {
    @property(Node) btn_select_widget:Node = null;
    @property(Node) lab_select_widget:Node = null;
    @property(Node) btn_delete:Node = null;
    @property(Node) edit_hurt:Node = null;
    protected m_call_back = null;
    protected m_data:da_guai_item_data = null;
    protected m_index:number = 0;
    public initView(data:da_guai_item_data,call,index){
        this.m_data = data;
        this.m_call_back = call;
        this.m_index = index;
        this.btn_select_widget.on(Node.EventType.TOUCH_END,()=>{
            let list =  Attributes.Singleton.get_cur_scene_all_only_widget()
            if(list.length<=0){
                return tools.showToast("当前场景没有添控件！")
            }
            tools.show_select_widget_list(list,(item:widget_item_data)=>{
                this.m_data.widget_id = item.att.id;
                this.updateShowStatus()
            },this.m_data.widget_id)
        })
        this.btn_delete.on(Node.EventType.TOUCH_END,()=>{
            if(this.m_call_back!=null){
                this.m_call_back(this)
            }
        })
        this.edit_hurt.on(EditBox.EventType.EDITING_DID_ENDED,()=>{
            this.m_data.hurt = parseInt(this.edit_hurt.getComponent(EditBox).string)
        })
        this.updateShowStatus()
    }

    public getIndex(){
       return this.m_index;
    }

    updateShowStatus(){
        this.edit_hurt.getComponent(EditBox).string = this.m_data.hurt.toString()
        this.lab_select_widget.getComponent(Label).string = this.m_data.widget_id!=-1?`当前选择的控件:${this.m_data.widget_id}`:"选择控件"
    }
}


