package com.dbs.consent.demo.activity.activityEvent;

import android.content.Context;
import android.content.Intent;
import android.graphics.PorterDuff;
import android.util.Log;
import android.view.View;

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

import com.dbs.consent.demo.R;
import com.dbs.consent.demo.activity.ConsentActivity;

public class TapMenu {

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

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

  /**
  * 각 탭을 클릭 했을때 배경색 및 아이콘 색상 변경
  * @author jksong
  * @since 2020-01-16 오전 9:22
   * 입원 : I, 외래 : O, 응급 : E, 수술 : OP, 검색 : S
  **/
  public void tapMenuColorChange(String indexPage) {
    if (indexPage.equals("I")) {
      instance.tabAdmission.setBackgroundColor(ContextCompat.getColor(mContext, R.color.leftBtnBgColor));
      instance.ivInPatient.setColorFilter(ContextCompat.getColor(mContext, R.color.leftBtnIvTvColor), PorterDuff.Mode.SRC_ATOP);
      instance.tvInPatient.setTextColor(ContextCompat.getColor(mContext, R.color.leftBtnIvTvColor));

      instance.tabOutPatient.setBackgroundColor(ContextCompat.getColor(mContext, R.color.white));
      instance.ivOutPatient.setColorFilter(ContextCompat.getColor(mContext, R.color.darkGray), PorterDuff.Mode.SRC_ATOP);
      instance.tvOutPatient.setTextColor(ContextCompat.getColor(mContext, R.color.darkGray));

      instance.tabEmergency.setBackgroundColor(ContextCompat.getColor(mContext, R.color.white));
      instance.ivErPatient.setColorFilter(ContextCompat.getColor(mContext, R.color.darkGray), PorterDuff.Mode.SRC_ATOP);
      instance.tvErPatient.setTextColor(ContextCompat.getColor(mContext, R.color.darkGray));

      instance.tabSurgery.setBackgroundColor(ContextCompat.getColor(mContext, R.color.white));
      instance.ivOpPatient.setColorFilter(ContextCompat.getColor(mContext, R.color.darkGray), PorterDuff.Mode.SRC_ATOP);
      instance.tvOpPatient.setTextColor(ContextCompat.getColor(mContext, R.color.darkGray));

      instance.tabSearch.setBackgroundColor(ContextCompat.getColor(mContext, R.color.white));
      instance.ivSearchPatient.setColorFilter(ContextCompat.getColor(mContext, R.color.darkGray), PorterDuff.Mode.SRC_ATOP);
      instance.tvSearchPatient.setTextColor(ContextCompat.getColor(mContext, R.color.darkGray));

      instance.tabAdmission.setEnabled(false);
      instance.tabOutPatient.setEnabled(true);
      instance.tabEmergency.setEnabled(true);
      instance.tabSurgery.setEnabled(true);
      instance.tabSearch.setEnabled(true);
    } else if (indexPage.equals("O")) {
      instance.tabAdmission.setBackgroundColor(ContextCompat.getColor(mContext, R.color.white));
      instance.ivInPatient.setColorFilter(ContextCompat.getColor(mContext, R.color.darkGray), PorterDuff.Mode.SRC_ATOP);
      instance.tvInPatient.setTextColor(ContextCompat.getColor(mContext, R.color.darkGray));

      instance.tabOutPatient.setBackgroundColor(ContextCompat.getColor(mContext, R.color.leftBtnBgColor));
      instance.ivOutPatient.setColorFilter(ContextCompat.getColor(mContext, R.color.leftBtnIvTvColor), PorterDuff.Mode.SRC_ATOP);
      instance.tvOutPatient.setTextColor(ContextCompat.getColor(mContext, R.color.leftBtnIvTvColor));

      instance.tabEmergency.setBackgroundColor(ContextCompat.getColor(mContext, R.color.white));
      instance.ivErPatient.setColorFilter(ContextCompat.getColor(mContext, R.color.darkGray), PorterDuff.Mode.SRC_ATOP);
      instance.tvErPatient.setTextColor(ContextCompat.getColor(mContext, R.color.darkGray));

      instance.tabSurgery.setBackgroundColor(ContextCompat.getColor(mContext, R.color.white));
      instance.ivOpPatient.setColorFilter(ContextCompat.getColor(mContext, R.color.darkGray), PorterDuff.Mode.SRC_ATOP);
      instance.tvOpPatient.setTextColor(ContextCompat.getColor(mContext, R.color.darkGray));

      instance.tabSearch.setBackgroundColor(ContextCompat.getColor(mContext, R.color.white));
      instance.ivSearchPatient.setColorFilter(ContextCompat.getColor(mContext, R.color.darkGray), PorterDuff.Mode.SRC_ATOP);
      instance.tvSearchPatient.setTextColor(ContextCompat.getColor(mContext, R.color.darkGray));

      instance.tabAdmission.setEnabled(true);
      instance.tabOutPatient.setEnabled(false);
      instance.tabEmergency.setEnabled(true);
      instance.tabSurgery.setEnabled(true);
      instance.tabSearch.setEnabled(true);
    } else if (indexPage.equals("E")) {
      instance.tabAdmission.setBackgroundColor(ContextCompat.getColor(mContext, R.color.white));
      instance.ivInPatient.setColorFilter(ContextCompat.getColor(mContext, R.color.darkGray), PorterDuff.Mode.SRC_ATOP);
      instance.tvInPatient.setTextColor(ContextCompat.getColor(mContext, R.color.darkGray));

      instance.tabOutPatient.setBackgroundColor(ContextCompat.getColor(mContext, R.color.white));
      instance.ivOutPatient.setColorFilter(ContextCompat.getColor(mContext, R.color.darkGray), PorterDuff.Mode.SRC_ATOP);
      instance.tvOutPatient.setTextColor(ContextCompat.getColor(mContext, R.color.darkGray));

      instance.tabEmergency.setBackgroundColor(ContextCompat.getColor(mContext, R.color.leftBtnBgColor));
      instance.ivErPatient.setColorFilter(ContextCompat.getColor(mContext, R.color.leftBtnIvTvColor), PorterDuff.Mode.SRC_ATOP);
      instance.tvErPatient.setTextColor(ContextCompat.getColor(mContext, R.color.leftBtnIvTvColor));

      instance.tabSurgery.setBackgroundColor(ContextCompat.getColor(mContext, R.color.white));
      instance.ivOpPatient.setColorFilter(ContextCompat.getColor(mContext, R.color.darkGray), PorterDuff.Mode.SRC_ATOP);
      instance.tvOpPatient.setTextColor(ContextCompat.getColor(mContext, R.color.darkGray));

      instance.tabSearch.setBackgroundColor(ContextCompat.getColor(mContext, R.color.white));
      instance.ivSearchPatient.setColorFilter(ContextCompat.getColor(mContext, R.color.darkGray), PorterDuff.Mode.SRC_ATOP);
      instance.tvSearchPatient.setTextColor(ContextCompat.getColor(mContext, R.color.darkGray));

      instance.tabAdmission.setEnabled(true);
      instance.tabOutPatient.setEnabled(true);
      instance.tabEmergency.setEnabled(false);
      instance.tabSurgery.setEnabled(true);
      instance.tabSearch.setEnabled(true);
    } else if (indexPage.equals("OP")) {
      instance.tabAdmission.setBackgroundColor(ContextCompat.getColor(mContext, R.color.white));
      instance.ivInPatient.setColorFilter(ContextCompat.getColor(mContext, R.color.darkGray), PorterDuff.Mode.SRC_ATOP);
      instance.tvInPatient.setTextColor(ContextCompat.getColor(mContext, R.color.darkGray));

      instance.tabOutPatient.setBackgroundColor(ContextCompat.getColor(mContext, R.color.white));
      instance.ivOutPatient.setColorFilter(ContextCompat.getColor(mContext, R.color.darkGray), PorterDuff.Mode.SRC_ATOP);
      instance.tvOutPatient.setTextColor(ContextCompat.getColor(mContext, R.color.darkGray));

      instance.tabEmergency.setBackgroundColor(ContextCompat.getColor(mContext, R.color.white));
      instance.ivErPatient.setColorFilter(ContextCompat.getColor(mContext, R.color.darkGray), PorterDuff.Mode.SRC_ATOP);
      instance.tvErPatient.setTextColor(ContextCompat.getColor(mContext, R.color.darkGray));

      instance.tabSurgery.setBackgroundColor(ContextCompat.getColor(mContext, R.color.leftBtnBgColor));
      instance.ivOpPatient.setColorFilter(ContextCompat.getColor(mContext, R.color.leftBtnIvTvColor), PorterDuff.Mode.SRC_ATOP);
      instance.tvOpPatient.setTextColor(ContextCompat.getColor(mContext, R.color.leftBtnIvTvColor));

      instance.tabSearch.setBackgroundColor(ContextCompat.getColor(mContext, R.color.white));
      instance.ivSearchPatient.setColorFilter(ContextCompat.getColor(mContext, R.color.darkGray), PorterDuff.Mode.SRC_ATOP);
      instance.tvSearchPatient.setTextColor(ContextCompat.getColor(mContext, R.color.darkGray));

      instance.tabAdmission.setEnabled(true);
      instance.tabOutPatient.setEnabled(true);
      instance.tabEmergency.setEnabled(true);
      instance.tabSurgery.setEnabled(false);
      instance.tabSearch.setEnabled(true);
    } else {
      instance.tabAdmission.setBackgroundColor(ContextCompat.getColor(mContext, R.color.white));
      instance.ivInPatient.setColorFilter(ContextCompat.getColor(mContext, R.color.darkGray), PorterDuff.Mode.SRC_ATOP);
      instance.tvInPatient.setTextColor(ContextCompat.getColor(mContext, R.color.darkGray));

      instance.tabOutPatient.setBackgroundColor(ContextCompat.getColor(mContext, R.color.white));
      instance.ivOutPatient.setColorFilter(ContextCompat.getColor(mContext, R.color.darkGray), PorterDuff.Mode.SRC_ATOP);
      instance.tvOutPatient.setTextColor(ContextCompat.getColor(mContext, R.color.darkGray));

      instance.tabEmergency.setBackgroundColor(ContextCompat.getColor(mContext, R.color.white));
      instance.ivErPatient.setColorFilter(ContextCompat.getColor(mContext, R.color.darkGray), PorterDuff.Mode.SRC_ATOP);
      instance.tvErPatient.setTextColor(ContextCompat.getColor(mContext, R.color.darkGray));

      instance.tabSurgery.setBackgroundColor(ContextCompat.getColor(mContext, R.color.white));
      instance.ivOpPatient.setColorFilter(ContextCompat.getColor(mContext, R.color.darkGray), PorterDuff.Mode.SRC_ATOP);
      instance.tvOpPatient.setTextColor(ContextCompat.getColor(mContext, R.color.darkGray));

      instance.tabSearch.setBackgroundColor(ContextCompat.getColor(mContext, R.color.leftBtnBgColor));
      instance.ivSearchPatient.setColorFilter(ContextCompat.getColor(mContext, R.color.leftBtnIvTvColor), PorterDuff.Mode.SRC_ATOP);
      instance.tvSearchPatient.setTextColor(ContextCompat.getColor(mContext, R.color.leftBtnIvTvColor));

      instance.tabAdmission.setEnabled(true);
      instance.tabOutPatient.setEnabled(true);
      instance.tabEmergency.setEnabled(true);
      instance.tabSurgery.setEnabled(true);
      instance.tabSearch.setEnabled(false);
    }
  }

  public View.OnClickListener onClickListener = new View.OnClickListener() {
    @Override
    public void onClick(View v) {
      Intent intent = new Intent(mContext, ConsentActivity.class);
      intent.putExtra("deptCd", instance.deptCd);
      intent.putExtra("deptNm", instance.deptNm);
      intent.putExtra("jobKindCd", instance.jobKindCd);
      intent.putExtra("jobKindNm", instance.jobKindNm);
      intent.putExtra("userId", instance.userId);
      intent.putExtra("userName", instance.userName);
      intent.putExtra("drKind", instance.indexPage);

      if (instance.tabAdmission == v){
        intent.putExtra("indexPage", "I");
      } else if (instance.tabOutPatient == v) {
        intent.putExtra("indexPage", "O");
      } else if (instance.tabEmergency == v) {
        intent.putExtra("indexPage", "E");
      } else if (instance.tabSurgery == v) {
        intent.putExtra("indexPage", "OP");
      } else if (instance.tabSearch == v) {
        intent.putExtra("indexPage", "SR");
      }

      mActivity.startActivity(intent);
      mActivity.finish();
      instance.tapClick = true;
    }
  };
}
