import { _decorator, Component, instantiate, Node, Prefab } from 'cc';
import { event_item } from '../../data/data';
import { show_select_evele_list_item } from './show_select_evele_list_item';
const { ccclass, property } = _decorator;

@ccclass('show_select_evele_list')
export class show_select_evele_list extends Component {
    @property(Node) content:Node = null;
    @property(Node) btn_close:Node = null;
    @property(Prefab) item_prefab:Prefab = null;
    private call_back = null;
    public show(list,call){
        this.call_back = call;
        for (let index = 0; index < list.length; index++) {
            const element = list[index];
            let item = instantiate(this.item_prefab)
            item.parent = this.content;
            item.getComponent(show_select_evele_list_item).initView(element,this.onItemClick.bind(this))
        }
        this.btn_close.on(Node.EventType.TOUCH_END,()=>{
            this.close()
        })
    }
    onItemClick(data:event_item){
       if(this.call_back!=null){
            this.call_back(data)
       }
       this.close()
    }

    close(){
        this.node.destroy()
    }
}


