package com.zxhl.main.page.view

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.RelativeLayout
import android.widget.TextView
import com.zxhl.cms.AppContext
import com.zxhl.cms.router.RounterApi
import com.zxhl.cms.router.RounterBus
import com.zxhl.cms.utils.JumpUtils
import com.zxhl.main.R
import org.jetbrains.anko.startActivity

/**
 * Created by gaoleichao on 2018/12/28
 */
class NavigationBottomView : RelativeLayout {
    constructor(context: Context?) : super(context) {
        init()
    }

    constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) {
        init()
    }

    constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(
        context,
        attrs,
        defStyleAttr
    ) {
        init()
    }

    private var mUserText: TextView? = null
    private var mVideoText: TextView? = null
    private var mWarehouseText: TextView? = null
    private var mShopText: TextView? = null
    private var navifationCallback: NavifationCallback? = null

    private fun init() {
        LayoutInflater.from(context).inflate(R.layout.view_navigation_bottom, this)
        mUserText = findViewById(R.id.id_view_navigation_bottom_user)
        mWarehouseText = findViewById(R.id.id_view_navigation_bottom_warehouse)
        mVideoText = findViewById(R.id.id_view_navigation_bottom_box)
        mShopText = findViewById(R.id.id_view_navigation_bottom_shop)
        mShopText?.setOnClickListener {
            mVideoText?.setTextColor(resources.getColor(R.color.color_333333))
            mUserText?.setTextColor(resources.getColor(R.color.color_333333))
            mWarehouseText?.setTextColor(resources.getColor(R.color.color_333333))
            mShopText?.setTextColor(resources.getColor(R.color.color_4c84ff))
            val userDrawable = getResources().getDrawable(R.drawable.icon_my_default)
            userDrawable.setBounds(
                0,
                0,
                userDrawable.getMinimumWidth(),
                userDrawable.getMinimumHeight()
            );

            val videoDrawable = getResources().getDrawable(R.drawable.icon_manghe_default)
            videoDrawable.setBounds(
                0,
                0,
                videoDrawable.getMinimumWidth(),
                videoDrawable.getMinimumHeight()
            )
            val warehouseDrawable = getResources().getDrawable(R.drawable.icon_huishou_default)
            warehouseDrawable.setBounds(
                0,
                0,
                videoDrawable.getMinimumWidth(),
                videoDrawable.getMinimumHeight()
            )
            val shopDrawable = getResources().getDrawable(R.drawable.icon_shangcheng_click)
            shopDrawable.setBounds(
                0,
                0,
                videoDrawable.getMinimumWidth(),
                videoDrawable.getMinimumHeight()
            )

            mUserText?.setCompoundDrawables(null, userDrawable, null, null)
            mVideoText?.setCompoundDrawables(null, videoDrawable, null, null)
            mWarehouseText?.setCompoundDrawables(null, warehouseDrawable, null, null)
            mShopText?.setCompoundDrawables(null, shopDrawable, null, null)
            navifationCallback?.onNavigationClick(it.id)
        }
        mUserText?.setOnClickListener {
//            if(true){
//                JumpUtils.activityJump(RounterBus.getRounter(RounterApi::class.java).getIntentActivityLogin())
//            } else {
            mVideoText?.setTextColor(resources.getColor(R.color.color_333333))
            mUserText?.setTextColor(resources.getColor(R.color.color_4c84ff))
            mWarehouseText?.setTextColor(resources.getColor(R.color.color_333333))
            mShopText?.setTextColor(resources.getColor(R.color.color_333333))
            val userDrawable = getResources().getDrawable(R.drawable.icon_my_click)
            userDrawable.setBounds(
                0,
                0,
                userDrawable.getMinimumWidth(),
                userDrawable.getMinimumHeight()
            );

            val videoDrawable = getResources().getDrawable(R.drawable.icon_manghe_default)
            videoDrawable.setBounds(
                0,
                0,
                videoDrawable.getMinimumWidth(),
                videoDrawable.getMinimumHeight()
            )
            val warehouseDrawable = getResources().getDrawable(R.drawable.icon_huishou_default)
            warehouseDrawable.setBounds(
                0,
                0,
                videoDrawable.getMinimumWidth(),
                videoDrawable.getMinimumHeight()
            )
            val shopDrawable = getResources().getDrawable(R.drawable.icon_shangcheng_default)
            shopDrawable.setBounds(
                0,
                0,
                videoDrawable.getMinimumWidth(),
                videoDrawable.getMinimumHeight()
            )

            mUserText?.setCompoundDrawables(null, userDrawable, null, null)
            mVideoText?.setCompoundDrawables(null, videoDrawable, null, null)
            mWarehouseText?.setCompoundDrawables(null, warehouseDrawable, null, null)
            mShopText?.setCompoundDrawables(null, shopDrawable, null, null)
            navifationCallback?.onNavigationClick(it.id)
//            }
        }
        mVideoText?.setOnClickListener {
            mVideoText?.setTextColor(resources.getColor(R.color.color_4c84ff))
            mUserText?.setTextColor(resources.getColor(R.color.color_333333))
            mWarehouseText?.setTextColor(resources.getColor(R.color.color_333333))
            mShopText?.setTextColor(resources.getColor(R.color.color_333333))
            val userDrawable = getResources().getDrawable(R.drawable.icon_my_default)
            userDrawable.setBounds(
                0,
                0,
                userDrawable.getMinimumWidth(),
                userDrawable.getMinimumHeight()
            );

            val videoDrawable = getResources().getDrawable(R.drawable.icon_manghe_click)
            videoDrawable.setBounds(
                0,
                0,
                videoDrawable.getMinimumWidth(),
                videoDrawable.getMinimumHeight()
            )
            val warehouseDrawable = getResources().getDrawable(R.drawable.icon_huishou_default)
            warehouseDrawable.setBounds(
                0,
                0,
                videoDrawable.getMinimumWidth(),
                videoDrawable.getMinimumHeight()
            )
            val shopDrawable = getResources().getDrawable(R.drawable.icon_shangcheng_default)
            shopDrawable.setBounds(
                0,
                0,
                videoDrawable.getMinimumWidth(),
                videoDrawable.getMinimumHeight()
            )
            mUserText?.setCompoundDrawables(null, userDrawable, null, null)
            mVideoText?.setCompoundDrawables(null, videoDrawable, null, null)
            mWarehouseText?.setCompoundDrawables(null, warehouseDrawable, null, null)
            mShopText?.setCompoundDrawables(null, shopDrawable, null, null)
            navifationCallback?.onNavigationClick(it.id)
        }
        mWarehouseText?.setOnClickListener {
            mVideoText?.setTextColor(resources.getColor(R.color.color_333333))
            mUserText?.setTextColor(resources.getColor(R.color.color_333333))
            mWarehouseText?.setTextColor(resources.getColor(R.color.color_4c84ff))

            mShopText?.setTextColor(resources.getColor(R.color.color_333333))
            val userDrawable = getResources().getDrawable(R.drawable.icon_my_default)
            userDrawable.setBounds(
                0,
                0,
                userDrawable.getMinimumWidth(),
                userDrawable.getMinimumHeight()
            );

            val videoDrawable = getResources().getDrawable(R.drawable.icon_manghe_default)
            videoDrawable.setBounds(
                0,
                0,
                videoDrawable.getMinimumWidth(),
                videoDrawable.getMinimumHeight()
            );
            val warehouseDrawable = getResources().getDrawable(R.drawable.icon_huishou_click)
            warehouseDrawable.setBounds(
                0,
                0,
                videoDrawable.getMinimumWidth(),
                videoDrawable.getMinimumHeight()
            )
            val shopDrawable = getResources().getDrawable(R.drawable.icon_shangcheng_default)
            shopDrawable.setBounds(
                0,
                0,
                videoDrawable.getMinimumWidth(),
                videoDrawable.getMinimumHeight()
            )
            mShopText?.setCompoundDrawables(null, shopDrawable, null, null)
            mUserText?.setCompoundDrawables(null, userDrawable, null, null)
            mVideoText?.setCompoundDrawables(null, videoDrawable, null, null)
            mWarehouseText?.setCompoundDrawables(null, warehouseDrawable, null, null)
            navifationCallback?.onNavigationClick(it.id)
        }
    }


    fun setNavifationCallback(navifationCallback: NavifationCallback) {
        this.navifationCallback = navifationCallback
    }


    interface NavifationCallback {

        fun onNavigationClick(vId: Int)
    }

}