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.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;

import java.util.ArrayList;

import kr.co.zumo.app.R;
import kr.co.zumo.app.lifeplus.bean.SignUpAgreeItemBean;
import kr.co.zumo.app.lifeplus.util.ResourceUtil;
import kr.co.zumo.app.lifeplus.view.CheckBoxAllDriver;


/**
 * SignUpAgreeFragment
 * <pre>
 * </pre>
 *
 * @author 하세미
 * @version 1.0
 * @history 하세미   [2018-09-21]   [최초 작성]
 * @since 2018-09-21
 */
public class SignUpAgreeFragment extends Fragment {

  private View itemView;
  private ArrayList<SignUpAgreeItemBean> items;
  private CheckBox checkBoxAll;
  private CheckBoxAllDriver checkBoxAllDriver;
  private int len;

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

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

  @Override
  public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    checkBoxAll = getView().findViewById(R.id.agree_check_all);
    checkBoxAllDriver = new CheckBoxAllDriver(checkBoxAll);

    checkBoxAll.setText(R.string.all_agree);
    checkBoxAll.setOnClickListener(v -> {
      checkBoxAllDriver.applyCheckAll(checkBoxAll.isChecked());
      checkAll(checkBoxAll.isChecked());
      notifyAgreeChanged();
    });


  }


  private CheckBox getCheckBoxByIndex(int index) {
    return itemView.findViewById(ResourceUtil.getId("agree_check" + index));
  }

  private void notifyAgreeChanged() {
  }

  private void notifyDetailPressed(int index, String data) {
    Log.i("APP# SignUpAgreeHolder | draw", "| index: " + index + ", data: " + data);

  }

  private void checkAll(boolean isChecked) {
    SignUpAgreeItemBean bean;
    for (int i = 0; i < len; ++i) {
      bean = items.get(i);
      bean.setChecked(isChecked);
    }
  }
}
