package com.dbs.mplus.fatima.activity.activityEvent;

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

import androidx.appcompat.app.AppCompatActivity;

import com.dbs.mplus.fatima.R;
import com.dbs.mplus.fatima.activity.ConsentActivity;
import com.dbs.mplus.fatima.activity.LoginActivity;
import com.dbs.mplus.fatima.consent.sign.SignWrapper;
import com.dbs.mplus.fatima.customView.CustomAlertDialog;
import com.dbs.mplus.fatima.customView.CustomSettingAlertDialog;
import com.dbs.mplus.fatima.util.Util;

public class TopMenu {
  private static final String TAG = "TopMenu";

  private AppCompatActivity mActivity;
  private Context mContext;
  private ConsentActivity instance;
  private CustomAlertDialog csAlert;

  public TopMenu(AppCompatActivity mActivity, Context mContext) {
    this.mActivity = mActivity;
    this.mContext = mContext;
    this.instance = (ConsentActivity) mContext;
    this.csAlert = new CustomAlertDialog(mContext);

  }

  public void setEvent() {
    instance.settingLayout.setOnClickListener(onClickListener);
    instance.logoutLayout.setOnClickListener(onClickListener);
  }

  private View.OnClickListener onClickListener = new View.OnClickListener() {
    @Override
    public void onClick(View view) {
      if (view == instance.settingLayout) {
        Log.e(TAG, "settingLayout");
        CustomSettingAlertDialog customSettingAlertDialog = new CustomSettingAlertDialog(mContext);
        customSettingAlertDialog.show();
      } else if (view == instance.logoutLayout) {
        Log.e(TAG, "logoutLayout");
        csAlert.show();
        csAlert.setContent(mContext.getString(R.string.logoutMsg), "");
        csAlert.btnConfirm.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            SignWrapper.getInstance().deleteAll();
            Util.clearPreference(mContext, "userInfo");
            Util.clearPreference(mContext, "sessionTime");
            Intent intent = new Intent(mContext, LoginActivity.class);
            mActivity.startActivity(intent);
            mActivity.finish();
          }
        });
        csAlert.btnCancel.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            csAlert.dismiss();
          }
        });
      }
    }
  };
}
