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

@ccclass('edit_event_more_delete_drag_other_item')
export class edit_event_more_delete_drag_other_item extends Component {
    @property(Node) lab_id:Node = null
    @property(Node) lab_remark:Node = null
    @property(EditBox) editbox:EditBox = null
    @property(Node) btn_delete:Node = null
    private m_data:event_item_delete_drag_other = null
    private m_delete_callback:Function
    start() {
        this.editbox.node.on(EditBox.EventType.EDITING_DID_ENDED, ()=> {
            if(this.editbox.string.length>0) {
                let index = parseInt(this.editbox.string)
                this.m_data.delete_drag_other_index = index;
            } else {
                this.m_data.delete_drag_other_index = -1;
            }
        })
        this.btn_delete.on(Node.EventType.TOUCH_END, ()=> {
            if(this.m_delete_callback!=null) {
                tools.show_dialog('删除?', ()=>{
                    this.m_delete_callback()
                })
            }
        })
    }

    initView(data:event_item_delete_drag_other, delete_callback:Function) {
        this.m_data = data
        this.m_delete_callback = delete_callback
        this.lab_id.getComponent(Label).string = 'id:' + data.widget_id
        if(data.widget_remark.length==0) {
            this.lab_id.setPosition(this.lab_remark.position.x,0,1)
        } else {
            this.lab_id.setPosition(this.lab_remark.position.x,25,1)
        }
        this.lab_remark.getComponent(Label).string = data.widget_remark
        if(data.delete_drag_other_index==-1) {
        } else {
            this.editbox.string = data.delete_drag_other_index.toString()
        }
    }
}

