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

@ccclass('event_more_scene_jump_assigned_page_event')
export class event_more_scene_jump_assigned_page_event extends Component {
    @property(EditBox) editBox_page:EditBox = null;
    @property(EditBox) editBox_interval_time:EditBox = null;
    @property(Node) btn_default_time:Node = null;
    private m_data:event_item_more_scene_jump_assigned_page_event = null;
    start() {
        this.editBox_page.node.on(EditBox.EventType.EDITING_DID_ENDED, ()=> {
            if(this.editBox_page.string.length>0){
                this.m_data.page_number = parseInt(this.editBox_page.string)
                this.updateStatus()
            }
        })
        this.editBox_interval_time.node.on(EditBox.EventType.EDITING_DID_ENDED, ()=> {
            if(this.editBox_interval_time.string.length>0) {
                this.m_data.interval_time = parseFloat(this.editBox_interval_time.string)
                this.updateStatus()
            }
        })
        this.btn_default_time.on(Node.EventType.TOUCH_END, ()=> {
            this.m_data.interval_time = event_item_more_scene_jump_assigned_page_event.defaultIntervalTime()
            this.updateStatus()
        })
    }

    initView(data:event_item_more_scene_jump_assigned_page_event) {
        this.m_data = data
        if(this.m_data.interval_time==undefined||this.m_data.interval_time==null) {
            this.m_data.interval_time = event_item_more_scene_jump_assigned_page_event.defaultIntervalTime()
        }
        this.updateStatus()
    }

    updateStatus() {
        if(this.m_data.page_number==-1) {
        } else {
            this.editBox_page.string = this.m_data.page_number.toString()
        }
        this.editBox_interval_time.string = this.m_data.interval_time.toString()
    }
}

