package com.airson.alive.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.airson.alive.R;
import com.airson.alive.activity.AddMedicalIDActivity;
import com.airson.alive.activity.MedicalIDActivity;
import com.airson.alive.interfaces.OnItemClickListener;
import com.airson.alive.model.MedicalIDsResponseModel;
import com.airson.alive.utils.AppConstants;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MedicalIDProfilesAdapter extends RecyclerView.Adapter<MedicalIDProfilesAdapter.MyViewHolder> {

    Context context;
    ArrayList<MedicalIDsResponseModel.MedicalIDDataSetFields>  array = null;

    public class MyViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.imageView)
        ImageView image;

        public MyViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);

        }
    }


    public MedicalIDProfilesAdapter(Context context, ArrayList<MedicalIDsResponseModel.MedicalIDDataSetFields>  array) {
        this.context = context;
        this.array = array;

    }

    @Override
    public MedicalIDProfilesAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.layout_home_item, parent, false);

        return new MedicalIDProfilesAdapter.MyViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(MedicalIDProfilesAdapter.MyViewHolder holder, final int position) {

        holder.image.setBackgroundResource(R.mipmap.add_profile);
        if (position==0){
            holder.image.setBackgroundResource(R.mipmap.add_profile);
        } else {
            holder.image.setBackgroundResource(R.mipmap.profile);
        }
        holder.image.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, AddMedicalIDActivity.class);
                    if (position == 0){
                        intent.putExtra("medicalID", "0");
                    } else {
                        intent.putExtra("medicalID", array.get(position).getMid());
                    }

                    context.startActivity(intent);

            }
        });

    }

    @Override
    public int getItemCount() {
        return array.size();
    }
}