package com.bonait.bnframework.common.view;

import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.bonait.bnframework.R;
import com.bonait.bnframework.common.helper.I.MyClickListener;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class BottomNavigationBar extends LinearLayout {

    //region 变量
    /**
     * 选中页面
     */
    public int SelectIndex = 1;

    /**
     * 点击事件
     */
    public MyClickListener mListener=null;

    @BindView(R.id.first)
    ImageView first;

    @BindView(R.id.z_bj)
    ImageView z_bj;

    @BindView(R.id.y_bj)
    ImageView y_bj;

    @BindView(R.id.z_wz)
    TextView z_wz;

    @BindView(R.id.y_wz)
    TextView y_wz;
    //endregion

    //region 私有
    private View root;

    public BottomNavigationBar(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        root = LayoutInflater.from(context).inflate(R.layout.bottom_navigation, this);
        ButterKnife.bind(this, root);
        SelectIndexTab(SelectIndex);
    }
    //endregion

    //region 数据处理
    @OnClick({R.id.z_wz,
            R.id.y_wz,R.id.first})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.z_wz:
                SelectIndex=0;
                break;
            case R.id.y_wz:
                SelectIndex=2;
                break;
            case R.id.first:
                SelectIndex=1;
                break;
        }
        SelectIndexTab(SelectIndex);
        if(mListener!=null)
        {
            mListener.clickListener(root,SelectIndex);
        }
    }
    //endregion

    //region 私有函数

    /**
     * 选中
     *
     * @param index
     */
    public void SelectIndexTab(int index) {
        switch (index) {
            case 1:
                z_bj.setVisibility(View.GONE);
                z_wz.setTextColor(Color.parseColor("#797373"));

                y_bj.setVisibility(View.GONE);
                y_wz.setTextColor(Color.parseColor("#797373"));

                first.setImageResource(R.mipmap.home_select);
                break;
            case 0:
                z_bj.setVisibility(View.VISIBLE);
                z_wz.setTextColor(Color.parseColor("#ffffff"));

                y_bj.setVisibility(View.GONE);
                y_wz.setTextColor(Color.parseColor("#797373"));

                first.setImageResource(R.mipmap.home_no);
                break;
            case 2:
                z_bj.setVisibility(View.GONE);
                z_wz.setTextColor(Color.parseColor("#797373"));

                y_bj.setVisibility(View.VISIBLE);
                y_wz.setTextColor(Color.parseColor("#ffffff"));

                first.setImageResource(R.mipmap.home_no);
                break;
        }
    }
    //endregion
}
