import { _decorator, Component, instantiate, Node, Prefab } from 'cc';
import { event_collect_event_item, event_item } from '../../../data/data';
import { Attributes } from '../Attributes';
import { tools } from '../../tools';
import { select_collect_event_item } from './select_collect_event_item';
import { collect_event_item } from './collect_event_item';
const { ccclass, property } = _decorator;

@ccclass('event_collect_event')
export class event_collect_event extends Component {
    private m_data:event_collect_event_item = null;
    @property(Node) btn_select_collect_event:Node = null;
    @property(Node) content:Node = null;
    @property(Prefab) item_prefab:Prefab = null;
    private _self_event_id:number = 0;
    public initView(data:event_collect_event_item,self_event_id:number){
        this.m_data = data;
        this._self_event_id = self_event_id;
        this.btn_select_collect_event.on(Node.EventType.TOUCH_END,()=>{
            let list =  Attributes.Singleton.getBeActionEventList()
            if(list.length<=0){
                return tools.showToast("没有可添加的事件")
            }
            tools.select_collect_event(list,(event_list:number[])=>{
                this.m_data.event_id_list =event_list;
                this.updateStatus()
            },this._self_event_id,this.m_data.event_id_list)
          
        })
        this.updateStatus()
    }

    updateStatus(){
        this.content.removeAllChildren()
        for (let index = 0; index <  this.m_data.event_id_list.length; index++) {
            const id =  this.m_data.event_id_list[index];
            let item = instantiate(this.item_prefab);
            item.parent = this.content;
            item.getComponent(collect_event_item).initView(id)
        }
    }
}


