import { _decorator, Component, Node, Size, UITransform, Vec3 } from 'cc';
import { config } from '../../config';
import { att_top_data, ui_att_item } from '../../../data/data';
import { view_not_have_interact } from './view_not_have_interact';
import { view_ui_att_item } from './view_ui_att_item';
import { view_interact_input } from './view_interact_input';
import { view_interact_page } from './view_interact_page';
import { view_interact_puzzle } from './view_interact_puzzle';
import { view_pointer_ding_wei } from './view_pointer_ding_wei';
import { view_wei_chi_pointer } from './view_wei_chi_pointer';
import { view_interact_scene } from './view_interact_scene';
import { view_boss_info } from './view_boss_info';
const { ccclass, property } = _decorator;

@ccclass('ui_top')
export class ui_top extends Component {
    @property(Node) interact_page:Node = null;
    @property(Node) interact_input:Node = null;
    @property(Node) interact_puzzle:Node = null;
    @property(Node) wei_chi_pointer:Node = null;
    @property(Node) pointer_ding_wei:Node = null;
    @property(Node) interact_scene:Node = null;
    @property(Node) not_have_interact:Node = null;
    @property(Node) boss_info:Node = null;
    @property(Node) btn_close:Node = null;
    @property(Node) btn_jump:Node = null;
    private view_map:Map<number,Node> = new Map;
    private m_data:att_top_data = null;
    public initView(data:att_top_data){
        this.m_data = data;
        this.view_map.set(config.top_view_type.interact_page,this.interact_page)
        this.view_map.set(config.top_view_type.interact_input,this.interact_input)
        this.view_map.set(config.top_view_type.interact_puzzle,this.interact_puzzle)
        this.view_map.set(config.top_view_type.wei_chi_pointer,this.wei_chi_pointer)
        this.view_map.set(config.top_view_type.pointer_ding_wei,this.pointer_ding_wei)
        this.view_map.set(config.top_view_type.interact_scene,this.interact_scene)
        this.view_map.set(config.top_view_type.not_have_interact,this.not_have_interact)
        this.view_map.set(config.top_view_type.boss_info,this.boss_info)
        this.updateStatus()
    }

    updateStatus(){
        this.hideAllTop()

        this.m_data.close_info = this.m_data.close_info?this.m_data.close_info:this.btn_close.getComponent(view_ui_att_item).getData();
        this.btn_close.getComponent(view_ui_att_item).updateAtt(this.m_data.close_info )

        this.m_data.jump_info = this.m_data.jump_info?this.m_data.jump_info:this.btn_jump.getComponent(view_ui_att_item).getData();
        this.btn_jump.getComponent(view_ui_att_item).updateAtt(this.m_data.jump_info )

        if(this.m_data.top_ui_type!=config.top_view_type.__null){
            this.view_map.get(this.m_data.top_ui_type).active = true;
        }

        this.btn_jump.active = this.m_data.is_open_jump;
        this.btn_close.active = this.m_data.is_open_close;
        this.showViewByType()
    }

    public changeData(data:att_top_data){
        this.m_data = data;
        this.updateStatus()
    }

    showViewByType(){
        switch (this.m_data.top_ui_type) {
            case config.top_view_type.not_have_interact:
                this.view_map.get(this.m_data.top_ui_type).getComponent(view_not_have_interact).updateView(this.m_data._not_have_interact_data)
                this.m_data._not_have_interact_data = this.view_map.get(this.m_data.top_ui_type).getComponent(view_not_have_interact).getData()
                break;
            case config.top_view_type.interact_input:
                this.view_map.get(this.m_data.top_ui_type).getComponent(view_interact_input).updateView(this.m_data._interact_input_data)
                this.m_data._interact_input_data = this.view_map.get(this.m_data.top_ui_type).getComponent(view_interact_input).getData()
                break;
            case config.top_view_type.interact_page:
                this.view_map.get(this.m_data.top_ui_type).getComponent(view_interact_page).updateView(this.m_data._interact_page_data)
                this.m_data._interact_page_data = this.view_map.get(this.m_data.top_ui_type).getComponent(view_interact_page).getData()
                break;
            case config.top_view_type.interact_puzzle:
                this.view_map.get(this.m_data.top_ui_type).getComponent(view_interact_puzzle).updateView(this.m_data._interact_puzzle_data)
                this.m_data._interact_puzzle_data = this.view_map.get(this.m_data.top_ui_type).getComponent(view_interact_puzzle).getData()
                break;
            case config.top_view_type.pointer_ding_wei:
                this.view_map.get(this.m_data.top_ui_type).getComponent(view_pointer_ding_wei).updateView(this.m_data._pointer_ding_wei_data)
                this.m_data._pointer_ding_wei_data = this.view_map.get(this.m_data.top_ui_type).getComponent(view_pointer_ding_wei).getData()
                break;
            case config.top_view_type.wei_chi_pointer:
                this.view_map.get(this.m_data.top_ui_type).getComponent(view_wei_chi_pointer).updateView(this.m_data._wei_chi_pointer_data)
                this.m_data._wei_chi_pointer_data = this.view_map.get(this.m_data.top_ui_type).getComponent(view_wei_chi_pointer).getData()
                break;
            case config.top_view_type.interact_scene:
                this.view_map.get(this.m_data.top_ui_type).getComponent(view_interact_scene).updateView(this.m_data._interact_scene_data)
                this.m_data._interact_scene_data = this.view_map.get(this.m_data.top_ui_type).getComponent(view_interact_scene).getData()
                break;
            case config.top_view_type.boss_info:
                this.view_map.get(this.m_data.top_ui_type).getComponent(view_boss_info).updateView(this.m_data._boss_info_data)
                this.m_data._boss_info_data = this.view_map.get(this.m_data.top_ui_type).getComponent(view_boss_info).getData()
                break;
        }
    }

    hideAllTop(){
        this.view_map.forEach((v,k)=>{
            v.active = false;
        })
    }
}


