package com.dbs.dbsec.activity.activityEvent;

import android.content.Context;
import android.graphics.PorterDuff;
import android.graphics.Typeface;
import android.graphics.drawable.GradientDrawable;
import android.view.View;

import com.dbs.dbsec.R;
import com.dbs.dbsec.activity.ConsentActivity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;

public class RightMenu {

  private static final String TAG = "RightMenu";
  private AppCompatActivity mActivity;
  private Context mContext;
  private ConsentActivity instance;

  public RightMenu(Context context, AppCompatActivity activity) {
    this.mActivity = activity;
    this.mContext  = context;
    this.instance  = (ConsentActivity) context;
  }

  public View.OnClickListener onClickListener = new View.OnClickListener() {
    @Override
    public void onClick(View v) {
      if(v == instance.historyLayout) {
        instance.viewPager.setCurrentItem(0);
      } else if(v == instance.markerLayout) {
        instance.viewPager.setCurrentItem(1);
      } else if(v == instance.searchLayout) {
        instance.viewPager.setCurrentItem(2);
      }
    }
  };

  public void rightMenuStartColor() {

    GradientDrawable historyBg = (GradientDrawable) instance.historyLayout.getBackground();
    GradientDrawable markerBg  = (GradientDrawable) instance.markerLayout.getBackground();
    GradientDrawable searchBg  = (GradientDrawable) instance.searchLayout.getBackground();

    markerBg.setColorFilter(ContextCompat.getColor(mContext, R.color.white), PorterDuff.Mode.SRC_ATOP);
    instance.tvRightMarker.setTextColor(ContextCompat.getColor(mContext, R.color.black));
    instance.tvRightMarker.setTypeface(null, Typeface.BOLD);

    historyBg.setColorFilter(ContextCompat.getColor(mContext, R.color.settingBtn), PorterDuff.Mode.SRC_ATOP);
    instance.tvRightHistory.setTextColor(ContextCompat.getColor(mContext, R.color.white));
    instance.tvRightHistory.setTypeface(null, Typeface.NORMAL);

    searchBg.setColorFilter(ContextCompat.getColor(mContext, R.color.settingBtn), PorterDuff.Mode.SRC_ATOP);
    instance.tvRightSearch.setTextColor(ContextCompat.getColor(mContext, R.color.white));
    instance.tvRightSearch.setTypeface(null, Typeface.NORMAL);
  }

  public void rightMenuColorChange(int position) {
    GradientDrawable historyBg = (GradientDrawable) instance.historyLayout.getBackground();
    GradientDrawable markerBg = (GradientDrawable) instance.markerLayout.getBackground();
    GradientDrawable searchBg = (GradientDrawable) instance.searchLayout.getBackground();

    if (position == 0) {
      historyBg.setColorFilter(ContextCompat.getColor(mContext, R.color.white), PorterDuff.Mode.SRC_ATOP);
      instance.tvRightHistory.setTextColor(ContextCompat.getColor(mContext, R.color.black));
      instance.tvRightHistory.setTypeface(null, Typeface.BOLD);

      markerBg.setColorFilter(ContextCompat.getColor(mContext, R.color.settingBtn), PorterDuff.Mode.SRC_ATOP);
      instance.tvRightMarker.setTextColor(ContextCompat.getColor(mContext, R.color.white));
      instance.tvRightMarker.setTypeface(null, Typeface.NORMAL);

      searchBg.setColorFilter(ContextCompat.getColor(mContext, R.color.settingBtn), PorterDuff.Mode.SRC_ATOP);
      instance.tvRightSearch.setTextColor(ContextCompat.getColor(mContext, R.color.white));
      instance.tvRightSearch.setTypeface(null, Typeface.NORMAL);

    } else if (position == 1) {
      markerBg.setColorFilter(ContextCompat.getColor(mContext, R.color.white), PorterDuff.Mode.SRC_ATOP);
      instance.tvRightMarker.setTextColor(ContextCompat.getColor(mContext, R.color.black));
      instance.tvRightMarker.setTypeface(null, Typeface.BOLD);

      historyBg.setColorFilter(ContextCompat.getColor(mContext, R.color.settingBtn), PorterDuff.Mode.SRC_ATOP);
      instance.tvRightHistory.setTextColor(ContextCompat.getColor(mContext, R.color.white));
      instance.tvRightHistory.setTypeface(null, Typeface.NORMAL);

      searchBg.setColorFilter(ContextCompat.getColor(mContext, R.color.settingBtn), PorterDuff.Mode.SRC_ATOP);
      instance.tvRightSearch.setTextColor(ContextCompat.getColor(mContext, R.color.white));
      instance.tvRightSearch.setTypeface(null, Typeface.NORMAL);

    } else if (position == 2) {
      searchBg.setColorFilter(ContextCompat.getColor(mContext, R.color.white), PorterDuff.Mode.SRC_ATOP);
      instance.tvRightSearch.setTextColor(ContextCompat.getColor(mContext, R.color.black));
      instance.tvRightSearch.setTypeface(null, Typeface.BOLD);

      historyBg.setColorFilter(ContextCompat.getColor(mContext, R.color.settingBtn), PorterDuff.Mode.SRC_ATOP);
      instance.tvRightHistory.setTextColor(ContextCompat.getColor(mContext, R.color.white));
      instance.tvRightHistory.setTypeface(null, Typeface.NORMAL);

      markerBg.setColorFilter(ContextCompat.getColor(mContext, R.color.settingBtn), PorterDuff.Mode.SRC_ATOP);
      instance.tvRightMarker.setTextColor(ContextCompat.getColor(mContext, R.color.white));
      instance.tvRightMarker.setTypeface(null, Typeface.NORMAL);
    }
  }
}