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

@ccclass('task_zhao_xi_jie')
export class task_zhao_xi_jie extends Component {
    @property(Node) btn_setting:Node = null;
    @property(Node) btn_setting_finish_event:Node = null;
    @property(Node) lab_setting_finish_event:Node = null;
    @property(Node) btn_select_type:Node = null;
    @property(Node) lab_select_type:Node = null;
    protected m_data:zhao_xi_jie_data = null;
    public updateView(data:zhao_xi_jie_data){
        this.m_data = data;
        this.btn_setting.off(Node.EventType.TOUCH_END);
        this.btn_setting.on(Node.EventType.TOUCH_END,()=>{
            tools.select_task_zhao_xi_jie(this.m_data)
        })

        this.btn_select_type.on(Node.EventType.TOUCH_END,()=>{
            tools.show_tip_type_select((type:number)=>{
                if(this.m_data.tip_type!=type){
                    this.m_data.tip_type = type;
                }
                this.updateStatus()
            })
        })

        this.btn_setting_finish_event.off(Node.EventType.TOUCH_END);
        this.btn_setting_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.updateStatus()
    }

    updateStatus(){
        if(this.m_data.finish_event_id==undefined){
            this.m_data.finish_event_id = -1;
        }
        this.lab_select_type.getComponent(Label).string = config.zhao_xi_jie_tip_type_map.get(this.m_data.tip_type)
        this.lab_setting_finish_event.getComponent(Label).string =  this.m_data.finish_event_id==-1?"暂未设置完成事件":`事件id:${this.m_data.finish_event_id}`
    }
}


