package com.dbs.consent.demo.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.consent.demo.R;
import com.dbs.consent.demo.activity.LoginActivity;
import com.dbs.consent.demo.consent.sign.SignWrapper;
import com.dbs.consent.demo.customView.CustomAlertDialog;
import com.dbs.consent.demo.customView.CustomSettingAlertDialog;
import com.dbs.consent.demo.util.Util;

public class TopMenu {

  private static final String TAG = "TopMenu";
  private AppCompatActivity mActivity;
  private Context mContext;

  private CustomAlertDialog csAlert;

  public TopMenu(Context context, AppCompatActivity activity) {
    this.mContext  = context;
    this.mActivity = activity;
    this.csAlert = new CustomAlertDialog(mContext);
  }

  public View.OnClickListener settingClickListener = new View.OnClickListener() {
    @Override
    public void onClick(View v) {
      CustomSettingAlertDialog customSettingAlertDialog = new CustomSettingAlertDialog(mContext);
      customSettingAlertDialog.show();
    }
  };

  public View.OnClickListener logoutClickListener = new View.OnClickListener() {
    @Override
    public void onClick(View v) {
      Log.e(TAG, "logoutClickListener");
      csAlert.show();
      csAlert.setContent(mContext.getString(R.string.logoutMsg), "");
      csAlert.btnConfirm.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
          csAlert.dismiss();
          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 v) {
          csAlert.dismiss();
        }
      });

    }
  };
}
