package kr.co.zumo.app.lifeplus.view.fragment.signup;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import kr.co.zumo.app.R;
import kr.co.zumo.app.lifeplus.model.SignUpModel;
import kr.co.zumo.app.lifeplus.view.Event;
import kr.co.zumo.app.lifeplus.view.ISignUpView;
import kr.co.zumo.app.lifeplus.view.custom.MobileAuthorizationView;
import kr.co.zumo.app.lifeplus.view.dialog.DialogBase;
import kr.co.zumo.app.lifeplus.view.dialog.IDialogResultListener;
import kr.co.zumo.app.lifeplus.view.fragment.FragmentBase;
import kr.co.zumo.app.lifeplus.view.presenter.signup.SignUpMobileAuthorizationPresenter;

/**
 * SignUpMobileAuthorizationFragment
 * <pre>
 * </pre>
 *
 * @author 하세미
 * @version 1.0
 * @history 하세미   [2018-09-27]   [최초 작성]
 * @since 2018-09-27
 */
public class SignUpMobileAuthorizationFragment extends FragmentBase<SignUpMobileAuthorizationPresenter> implements ISignUpView {

  private MobileAuthorizationView authView;

  @Override
  public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
  }

  @Nullable
  @Override
  public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    return inflater.inflate(R.layout.fragment_sign_up_mobile_authorization, container, false);
  }

  @Override
  protected void onAfterActivityCreated(Bundle savedInstanceState) {

    authView = new MobileAuthorizationView(getContext(), new IDialogResultListener() {
      @Override
      public void onDialogResult(DialogBase dialog, Event event) {
        presenter.onEvent(event);
      }

      @Override
      public void onDialogCanceled(DialogBase dialog) {
        presenter.onEvent(new Event.Builder(Event.CANCEL).build());

      }
    });

    LinearLayout layout = getView().findViewById(R.id.container);
    layout.addView(authView);

  }

  @Override
  protected SignUpMobileAuthorizationPresenter definePresenter() {
    return new SignUpMobileAuthorizationPresenter(getModel(SignUpModel.class), this);
  }


  @Override
  public void onDestroyView() {
    super.onDestroyView();

    if (null != authView) {
      authView.dispose();
    }
  }
}
