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

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import java.util.ArrayList;

import kr.co.zumo.app.R;
import kr.co.zumo.app.lifeplus.bean.TextImageBean;

/**
 * SettingExpandableListViewAdapter
 * <pre>
 * </pre>
 *
 * @author 하세미
 * @version 1.0
 * @history 하세미   [2018-10-10]   [최초 작성]
 * @since 2018-10-10
 */
public class SettingExpandableListViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

  private ArrayList<TextImageBean> settingList;
  private Context context;


  public SettingExpandableListViewAdapter(Context context) {
    this.context = context;
  }


  @NonNull
  @Override
  public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
    View view;
    switch (viewType) {
      case 0:
        view = LayoutInflater
          .from(parent.getContext())
          .inflate(R.layout.setting_custom_menu1, parent, false);
        return new defaultSettingViewHolder(view);
      case 1:
        view = LayoutInflater
          .from(parent.getContext())

          .inflate(R.layout.setting_custom_menu2, parent, false);
        return new codeManageViewHolder(view);
      case 2:
        view = LayoutInflater
          .from(parent.getContext())
          .inflate(R.layout.setting_custom_menu3, parent, false);
        return new pushAndLocationSettingViewHolder(view);
      case 3:
        view = LayoutInflater
          .from(parent.getContext())
          .inflate(R.layout.setting_custom_menu4, parent, false);
        return new agreeInformationViewHolder(view);
      default:
        break;
    }

    return null;
  }

  @Override
  public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
    switch (position) {
      case 0:
        ((defaultSettingViewHolder) holder).imageViewAccordion.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            ((defaultSettingViewHolder) holder).onClick();
          }
        });
        break;
      case 1:
        ((codeManageViewHolder) holder).imageViewAccordion.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            ((codeManageViewHolder) holder).onClick();
          }
        });
        break;
      case 2:
        ((pushAndLocationSettingViewHolder) holder).imageViewAccordion.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            ((pushAndLocationSettingViewHolder) holder).onClick();
          }
        });
        break;
      case 3:
        ((agreeInformationViewHolder) holder).imageViewAccordion.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            ((agreeInformationViewHolder) holder).onClick();
          }
        });
        break;
      default:
        break;
    }

  }

  @Override
  public int getItemViewType(int position) {
    return position;
  }

  @Override
  public int getItemCount() {
    return 4;
  }

  private class defaultSettingViewHolder extends RecyclerView.ViewHolder {

    private RelativeLayout customLayout;
    private ImageView imageViewAccordion;

    public defaultSettingViewHolder(View itemView) {
      super(itemView);
      customLayout = itemView.findViewById(R.id.layout_default_setting);
      imageViewAccordion = itemView.findViewById(R.id.image_view_setting_menu_accordion);
    }

    public void onClick() {
      customLayout.setVisibility(customLayout.getVisibility() == View.GONE ? View.VISIBLE : View.GONE);
      imageViewAccordion.setImageResource(customLayout.getVisibility() == View.GONE ? R.drawable.icon_arcordion_open_arrow : R.drawable.icon_arcordion_close_arrow);

    }


  }

  private class codeManageViewHolder extends RecyclerView.ViewHolder {
    private RelativeLayout customLayout;
    private ImageView imageViewAccordion;

    public codeManageViewHolder(View itemView) {
      super(itemView);
      customLayout = itemView.findViewById(R.id.layout_code_manage);
      imageViewAccordion = itemView.findViewById(R.id.image_view_setting_menu_accordion);

    }

    public void onClick() {
      customLayout.setVisibility(customLayout.getVisibility() == View.GONE ? View.VISIBLE : View.GONE);
      imageViewAccordion.setImageResource(customLayout.getVisibility() == View.GONE ? R.drawable.icon_arcordion_open_arrow : R.drawable.icon_arcordion_close_arrow);
    }
  }

  private class pushAndLocationSettingViewHolder extends RecyclerView.ViewHolder {
    private RelativeLayout customLayout;
    private ImageView imageViewAccordion;

    public pushAndLocationSettingViewHolder(View itemView) {
      super(itemView);
      customLayout = itemView.findViewById(R.id.layout_push_location_setting);
      imageViewAccordion = itemView.findViewById(R.id.image_view_setting_menu_accordion);

    }

    public void onClick() {
      customLayout.setVisibility(customLayout.getVisibility() == View.GONE ? View.VISIBLE : View.GONE);
      imageViewAccordion.setImageResource(customLayout.getVisibility() == View.GONE ? R.drawable.icon_arcordion_open_arrow : R.drawable.icon_arcordion_close_arrow);
    }
  }

  private class agreeInformationViewHolder extends RecyclerView.ViewHolder {
    private RelativeLayout customLayout;
    private ImageView imageViewAccordion;

    public agreeInformationViewHolder(View itemView) {
      super(itemView);
      customLayout = itemView.findViewById(R.id.layout_agree_information);
      imageViewAccordion = itemView.findViewById(R.id.image_view_setting_menu_accordion);
    }

    public void onClick() {
      customLayout.setVisibility(customLayout.getVisibility() == View.GONE ? View.VISIBLE : View.GONE);
      imageViewAccordion.setImageResource(customLayout.getVisibility() == View.GONE ? R.drawable.icon_arcordion_open_arrow : R.drawable.icon_arcordion_close_arrow);
    }
  }
}
