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

import android.view.View;
import android.widget.Button;

import kr.co.zumo.app.R;
import kr.co.zumo.app.lifeplus.view.Event;
import kr.co.zumo.app.lifeplus.bean.SignUpButtonBean;
import kr.co.zumo.app.lifeplus.view.presenter.signup.SignUpItem;

/**
 * SignUpButtonHolder
 * <pre>
 * </pre>
 *
 * @author 민효동
 * @version 1.0
 * @history 민효동   [2018. 9. 12.]   [최초 작성]
 * @since 2018. 9. 12.
 */
public class SignUpButtonHolder extends BaseViewHolder {
  Button button;

  public SignUpButtonHolder(View itemView) {
    super(itemView);
  }

  @Override
  void draw(SignUpItem item) {
    SignUpButtonBean bean = item.getBean(SignUpButtonBean.class);
    String text = bean.getText();
    int buttonId = bean.getButtonId();
    ISignUpHolderEventListener listener = item.getEventListener();

    button = itemView.findViewById(R.id.sign_up_button);
    button.setEnabled(true);
    button.setText(text);
    button.setOnClickListener(v -> {
      button.setEnabled(false);
      if (null != listener) {
        listener.onSignUpHolderEvent(SignUpButtonHolder.this, Event.CLICK, buttonId);
      }
    });
  }

  @Override
  public void setDisabled() {
    button.setEnabled(false);
  }

  @Override
  public void setEnabled() {
    button.setEnabled(true);
  }
}
