import { _decorator, Color, Component, EditBox, instantiate, Label, Node, Prefab, Toggle } from 'cc';
import { config } from '../config';
import { sceme_type_select_item } from '../sceme_type_select_item';
import { scene_item_data } from '../../data/data';
import { tools } from '../tools';
const { ccclass, property } = _decorator;

@ccclass('add_scene')
export class add_scene extends Component {
    @property(Node) btn_sure:Node = null;
    @property(Node) btn_cancel:Node = null;
    @property(EditBox) EditBox_Scene_Name:EditBox = null;
    @property(Node) btn_scene_template:Node = null;
    @property(Node) scene_template:Node = null;
    // @property(Node) btn_close_scene_type:Node = null;
    @property(Node) btn_close_scene_template:Node = null;
    @property(Prefab) sceme_type_select_item_prefab:Prefab = null;
    @property(Node) scene_template_content:Node = null;

    @property(Node) lab_danye:Node = null;
    @property(Node) lab_duoye_shangxia:Node = null;
    @property(Node) lab_duoye_zuoyou:Node = null;

    @property(Toggle) tg_child_scene:Toggle = null;

    private select_type:number = config.Scene_Type_List.single_screen;

    private def_select_scene_item_data:scene_item_data = new scene_item_data("",0);
    private m_call_back = null;
    public initView(call_back){
        this.m_call_back = call_back;
        this.btn_sure.on(Node.EventType.TOUCH_END,()=>{
            if(this.EditBox_Scene_Name.string.length<=0){
                return tools.showToast("请填写场景名字！")
            }
            this.def_select_scene_item_data.scene_diy_name = this.EditBox_Scene_Name.string
            this.def_select_scene_item_data.type = this.select_type
            this.def_select_scene_item_data.is_child_scene = this.tg_child_scene.isChecked
            if(this.m_call_back!=null){
                if( this.def_select_scene_item_data.is_child_scene){
                    this.def_select_scene_item_data.scene_diy_name = `${this.def_select_scene_item_data.scene_diy_name}(子场景)`
                }
                this.m_call_back(this.def_select_scene_item_data)
            }
            this.close()
        })
        this.btn_cancel.on(Node.EventType.TOUCH_END,()=>{
            this.close()
        })
        this.btn_scene_template.on(Node.EventType.TOUCH_END,()=>{
            // this.scene_template.active = true;
        })    
        this.btn_close_scene_template.on(Node.EventType.TOUCH_END,()=>{
            this.scene_template.active = false;
        }) 

        this.lab_danye.on(Node.EventType.TOUCH_END,()=>{
            this.select_type = config.Scene_Type_List.single_screen;
            this.updaetSelect()
        })
        this.lab_duoye_shangxia.on(Node.EventType.TOUCH_END,()=>{
            this.select_type = config.Scene_Type_List.many_screen_switch_up_down;
            this.updaetSelect()
        })
        this.lab_duoye_zuoyou.on(Node.EventType.TOUCH_END,()=>{
            this.select_type = config.Scene_Type_List.many_screen_switch_left_right;
            this.updaetSelect()
        })
        config.init()
        this.updaetSelect()
        // this.initSelectSceneTypes() 
    }
    updaetSelect(){
        this.lab_danye.getComponent(Label).color = Color.BLACK
        this.lab_duoye_shangxia.getComponent(Label).color = Color.BLACK
        this.lab_duoye_zuoyou.getComponent(Label).color = Color.BLACK
        switch(this.select_type){
            case config.Scene_Type_List.single_screen:
                this.lab_danye.getComponent(Label).color = Color.RED
                break;
            case config.Scene_Type_List.many_screen_switch_up_down:
                this.lab_duoye_shangxia.getComponent(Label).color = Color.RED
                break;
            case config.Scene_Type_List.many_screen_switch_left_right:
                this.lab_duoye_zuoyou.getComponent(Label).color = Color.RED
                break;         
        }
    }
    initSelectSceneTypes(){
        // this.scene_type_content.removeAllChildren()
        // config.SceneType.forEach((v,k)=>{
        //     if(this.def_select_scene_item_data==null){
        //         this.def_select_scene_item_data = v;
        //     }
        //     let item = instantiate(this.sceme_type_select_item_prefab)
        //     item.parent = this.scene_type_content
        //     item.getComponent(sceme_type_select_item).initView(v,this.onSelectSceneTypeItemClick.bind(this))
        // })

        // if(this.def_select_scene_item_data!=null){
        //     this.lab_cur_select_scene_name.getComponent(Label).string = this.def_select_scene_item_data.name;
        // }
    }

    onSelectSceneTypeItemClick(item:sceme_type_select_item){
        // this.def_select_scene_item_data = item.getData()
        // this.lab_cur_select_scene_name.getComponent(Label).string = `${this.def_select_scene_item_data.name}${this.def_select_scene_item_data.is_check_mask?"-勾选遮罩":""}`;
    }
    close(){
        this.node.removeFromParent()
    }
}


