import { _decorator, Component, Node } from 'cc';
import { zhao_xi_jie_data, zhao_xi_jie_item_data } from '../../../data/data';
import { config } from '../../config';
import { tip_type_single } from './tip_type_single';
import { tip_type_all } from './tip_type_all';
import { shouji_item } from './shouji_item';
import { ClientEvent } from '../../clientEvent';
import { gameManager } from '../gameManager';
const { ccclass, property } = _decorator;

@ccclass('ui_manifestations')
export class ui_manifestations extends Component {
    @property(Node) tip_type_single:Node = null;
    @property(Node) tip_type_all:Node = null;
    @property(Node) btn_single_click_hide_tip:Node = null;
    private mData:zhao_xi_jie_data = null;
    public initView(data:zhao_xi_jie_data){
        this.mData = data;
        if(this.mData.tip_type===config.zhao_xi_jie_tip_type.select_tips){
            this.tip_type_single.active = true;
            this.btn_single_click_hide_tip.active = false;
            this.btn_single_click_hide_tip.on(Node.EventType.TOUCH_END,()=>{
                this.btn_single_click_hide_tip.active = false;
                this.tip_type_single.getComponent(tip_type_single).hideTipBtn()
            })
            this.tip_type_all.active = false;
            this.tip_type_single.getComponent(tip_type_single).initView(data,this.onItemClick.bind(this),this.onItemTips.bind(this))
        }else{
            this.tip_type_all.active = true;
            this.tip_type_single.active = false;
            this.tip_type_all.getComponent(tip_type_all).initView(data,this.onShowTips.bind(this))
        }
        ClientEvent.on(config.EventRun.SHOW_ZHAO_BU_TONG_FINISH_STATUS,this.on_zhao_bu_tong_finish.bind(this),this)
        ClientEvent.on(config.EventRun.ON_ZHAO_BU_TONG_ALL_FINISH,this.on_zhao_bu_tong_all_finish.bind(this),this)
    }

    on_zhao_bu_tong_finish(widget:zhao_xi_jie_item_data){
        if(this.mData.tip_type===config.zhao_xi_jie_tip_type.select_tips){
            this.tip_type_single.getComponent(tip_type_single).showFinishIcon(widget.widget_id)
        }else{
            this.tip_type_all.getComponent(tip_type_all).showFinishIcon(widget.widget_id)
        }
    }
    on_zhao_bu_tong_all_finish(data: zhao_xi_jie_data) {
        let delay_time = zhao_xi_jie_data.finish_widget_hidden_delay_time * 1000
        setTimeout(()=> {
            this.node.active = false
        }, delay_time)
    }
    onItemClick(){
        this.btn_single_click_hide_tip.active = true;
    }

    public onItemTips(data:zhao_xi_jie_item_data){
        ClientEvent.dispatchEvent(config.EventRun.SHOW_TIPS,data.tips_res)
    }
    public onShowTips(){
        gameManager.Singleton.showTips()
    }
} 


