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

@ccclass('select_ui_top_type')
export class select_ui_top_type 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.top_view_type_map.forEach((v,k)=>{
            if(k!=config.top_view_type.__null){
                let item = instantiate(this.item_prefab)
                item.parent = this.content;
                item.getComponent(select_ui_top_type_item).initView(k,this.onItemClick.bind(this))
            }
        })
        this.btn_close.on(Node.EventType.TOUCH_END,()=>{
            this.close()
        })
    }
    onItemClick(type:number){
       if(this.call_back!=null){
            tools.show_dialog("选择后不可更改，是否确定？",()=>{
                this.call_back(type)
                this.close()
            })
       } 

    }

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


