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

@ccclass('tip_type_select')
export class tip_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.zhao_xi_jie_tip_type_map.forEach((v,k)=>{
            let item = instantiate(this.item_prefab)
            item.parent = this.content;
            item.getComponent(slide_dir_select_item).initTipView(k,v,this.onItemClick.bind(this))
        })
        this.btn_close.on(Node.EventType.TOUCH_END,()=>{
            this.close()
        })
    }
    onItemClick(dir:number){
       if(this.call_back!=null){
            this.call_back(dir)
       } 
       this.close()
    }
    close(){
        this.node.destroy()
    }
}


