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

@ccclass('edit_event_group_item')
export class edit_event_group_item extends Component {
    @property(Node) btn_delete:Node = null;
    @property(Node) lab_event_id:Node = null;
    @property(EditBox) editBox_delay_time:EditBox = null;
    @property(Node) btn_up:Node = null;
    @property(Node) btn_down:Node = null;
    private m_index:number = 0
    private m_data:event_group_event_item_event_item = null;
    private m_delete_callback:Function = null;
    private m_operation_callback:Function = null;
    start() {
        this.editBox_delay_time.node.on(EditBox.EventType.EDITING_DID_ENDED, ()=> {
            if(this.editBox_delay_time.string.length == 0) {
                this.editBox_delay_time.string = '0'
            }
            this.m_data.delay_time = parseFloat(this.editBox_delay_time.string)
        })
        this.btn_delete.on(Node.EventType.TOUCH_END, ()=> {
            if(this.m_delete_callback!=null) {
                this.m_delete_callback()
            }
        })
        this.btn_up.on(Node.EventType.TOUCH_END, ()=>{
            if(this.m_operation_callback!=null) {
                this.m_operation_callback(this,true)
            }
        })
        this.btn_down.on(Node.EventType.TOUCH_END, ()=>{
            if(this.m_operation_callback!=null) {
                this.m_operation_callback(this,false)
            }
        })
    }

    initView(index:number, total_count:number, data:event_group_event_item_event_item, delete_callback:Function, operation_callback:Function) {
        this.m_index = index
        this.m_data = data
        this.m_delete_callback = delete_callback
        this.m_operation_callback = operation_callback
        this.lab_event_id.getComponent(Label).string = `事件名:${this.m_data.event_item.event_name}-id:${this.m_data.event_item.event_id}`
        this.editBox_delay_time.string = this.m_data.delay_time.toString()
        if(index == 0) {
            this.btn_up.active = false
        } else {
            this.btn_up.active = true
        }

        if(index < total_count - 1) {
            this.btn_down.active = true
        } else {
            this.btn_down.active = false
        }
    }

    getIndex():number{
        return this.m_index
    }

}

