/*
 * COPYRIGHT (c) 2018 All rights reserved by HANWHA LIFE.
 */
package kr.co.zumo.app.lifeplus.activity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import kr.co.zumo.app.R;
import kr.co.zumo.app.lifeplus.manager.ActionBarManager;
import kr.co.zumo.app.lifeplus.model.MainModel;
import kr.co.zumo.app.lifeplus.model.SuperModel;
import kr.co.zumo.app.lifeplus.util.AppUtil;
import kr.co.zumo.app.lifeplus.view.Event;
import kr.co.zumo.app.lifeplus.view.IMainView;
import kr.co.zumo.app.lifeplus.view.dialog.DialogBase;
import kr.co.zumo.app.lifeplus.view.dialog.DialogBuilder;
import kr.co.zumo.app.lifeplus.view.dialog.DialogID;
import kr.co.zumo.app.lifeplus.view.dialog.IDialogResultListener;
import kr.co.zumo.app.lifeplus.view.presenter.MainPresenter;

/**
 * MainActivity
 * <pre>
 * </pre>
 *
 * @author 민효동
 * @version 1.0
 * @history 민효동   [2018. 9. 5.]   [최초 작성]
 * @since 2018. 9. 5.
 */
public class MainActivity extends ActivityBase<MainPresenter> implements IMainView {

  @Override
  void onAfterCreate(Bundle savedInstanceState) {

    setContentView(R.layout.activity_main);

    Button button;
    button = findViewById(R.id.button_clear);
    if (AppUtil.isDebug()) {
      button.setOnClickListener(v -> {
        SuperModel.getInstance().getPreferences().setPermissionInfoDone(false);
        SuperModel.getInstance().getPreferences().setTutorialDone(false);
        SuperModel.getInstance().getPreferences().setUserId("");
        SuperModel.getInstance().getPreferences().setDeviceUuid("");
        SuperModel.getInstance().getPreferences().setEncryptedPin("");
        SuperModel.getInstance().getPreferences().setZumoUserUpdateCompleted(false);
      });
    }
    else {
      button.setVisibility(View.GONE);
    }

    button = findViewById(R.id.button_sign_up);
    button.setOnClickListener(v -> {
      presenter.onEvent(new Event.Builder(Event.SIGN_UP).build());
    });
//
//    button = findViewById(R.id.button_test);
//    button.setOnClickListener(v -> {
//      showAddRegistrationDialog();
//    });

  }

  @Override
  protected void onDestroy() {
    super.onDestroy();
  }

  @Override
  void defineActionBar() {
    ActionBarManager actionBarManager = ActionBarManager.getInstance();
    actionBarManager.setTitle(R.string.main_text);
    actionBarManager.setDisplayHomeAsUpEnabled(false);
    actionBarManager.hide();
  }

  @Override
  MainPresenter definePresenter() {
    return new MainPresenter(getModel(MainModel.class), this);
  }

  private void showAddRegistrationDialog() {
    DialogBase dialog = DialogBuilder.create(DialogID.ADD_REGISTRATION)
      .listener(new IDialogResultListener() {
        @Override
        public void onDialogResult(DialogBase dialog, Event event) {
          switch (event.getEventId()) {
            case Event.EMAIL_CLICK:
              Log.e("APP#  MainFragment | onDialogResult", "|" + "add email button click");
              break;
            case Event.SPECIAL_CODE_CLICK:
              Log.e("APP#  MainFragment | onDialogResult", "|" + "special code button click");
              break;
            default:
              break;
          }
        }

        @Override
        public void onDialogCanceled(DialogBase dialog) {

        }
      })
      .show();
  }

}

