import { _decorator, Component, Node, Animation } from 'cc';
import { base_ui } from '../../fw/base_ui';
import { uiManager } from '../../manager/uiManager';
import { config } from '../../config';
import { home_modules_more } from './home_modules_more';
import { tools } from '../../tools';
const { ccclass, property } = _decorator;

@ccclass('home_modules')
export class home_modules extends base_ui {
    @property(Node) btn_qiandao:Node = null
    @property(Node) btn_gengduo:Node = null
    @property(Node) btn_cheku:Node = null
    @property(Node) btn_beibao:Node = null
    @property(Node) node_gengduo:Node = null

    @property(Node) img_dot_qiandao:Node = null
    @property(Node) img_dot_gengduo:Node = null

    start() {
        this.onButtonListen(this.btn_qiandao, ()=>{
            uiManager.Instance().showUi(config.UI.ui_sign_view)
        })
        this.onButtonListen(this.btn_gengduo, ()=>{
            this.node_gengduo.active = !this.node_gengduo.active
            if(this.node_gengduo.active) {
                this.node_gengduo.getComponent(Animation).play()
            } 
        })
        this.onButtonListen(this.btn_cheku, ()=>{
            this.node.parent.active = false
            uiManager.Instance().showUi(config.UI.car_lib, null, ()=>{
                this.node.parent.active = true
            })
        })
        this.onButtonListen(this.btn_beibao, ()=>{
            uiManager.Instance().showUi(config.UI.bag)
        })
        this.node_gengduo.active = false

        this.startAnimation()
    }

    public init() {
        let data = tools.user_red_dot_data
        this.showRedDotQiandao(data.sign_red_dot==1?true:false)
        this.showRedDotGonggao(data.bulletin_red_dot==1?true:false)

        let is_mail_read = tools.user_red_dot_data.mail_unread_number>0?true:false
        this.showRedDotYoujian(is_mail_read)
    }

    private startAnimation() {
        setTimeout(()=>{
            this.btn_qiandao.getComponent(Animation).play()
            this.btn_gengduo.getComponent(Animation).play()
            this.btn_cheku.getComponent(Animation).play()
            this.btn_beibao.getComponent(Animation).play()
        },200)
    }
    
    public showRedDotQiandao(is_show:boolean) {
        this.img_dot_qiandao.active = is_show
    }

    public showRedDotYoujian(is_show:boolean) {
        this.node_gengduo.getComponent(home_modules_more).showRedDotYoujian(is_show)
        this.checkRedDotMore()
    }

    public showRedDotGonggao(is_show:boolean) {
        this.node_gengduo.getComponent(home_modules_more).showRedDotGonggao(is_show)
        this.checkRedDotMore()
    }

    private checkRedDotMore() {
       let is_show = this.node_gengduo.getComponent(home_modules_more).getDotAllShow()
       this.img_dot_gengduo.active = is_show
    }
}

