import { _decorator, Component, instantiate, Node, Prefab } from 'cc';
import { config } from './config';
import { click_type_select_item } from './click_type_select_item';
const { ccclass, property } = _decorator;

@ccclass('click_type_select')
export class click_type_select 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(call){
        this.call_back = call;
        config.clcik_type_map.forEach((v,k)=>{
            let item = instantiate(this.item_prefab)
            item.parent = this.content;
            item.getComponent(click_type_select_item).initView(k,this.onItemClick.bind(this))
        })
        this.btn_close.on(Node.EventType.TOUCH_END,()=>{
            this.close()
        })
    }
    onItemClick(type:number){
        console.log("onItemClick",type)
       if(this.call_back!=null){
            this.call_back(type)
       } 
       this.close()
    }

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


