package com.project.ilsaenterprise.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.project.ilsaenterprise.R;
import com.project.ilsaenterprise.models.ContactModel;
import com.squareup.picasso.Picasso;
import java.util.List;

import de.hdodenhof.circleimageview.CircleImageView;

public class ContactAdapter extends ArrayAdapter<ContactModel> {
    private static final String TAG = "Chat Adapter" ;
    private Context context;
    private List<ContactModel> contactList;

    public ContactAdapter(List<ContactModel> contactList, Context context){
        super(context, R.layout.row_contact, contactList);
        this.context = context;
        this.contactList = contactList;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent){
        viewHolder holder;

        LayoutInflater inflater = LayoutInflater.from(context);
        convertView = inflater.inflate(R.layout.row_contact, null, true);
        holder = new viewHolder();

        holder.nama = convertView.findViewById(R.id.namaKontak);
        holder.jabatan = convertView.findViewById(R.id.jabatanKontak);
        holder.penempatan = convertView.findViewById(R.id.penempatanKontak);
        holder.email = convertView.findViewById(R.id.emailKontak);
        holder.image = convertView.findViewById(R.id.imageContact);
        convertView.setTag(holder);

        ContactModel contact = contactList.get(position);

        Picasso.get().load(contact.getImage()).placeholder(R.drawable.employee_img).into(holder.image);

        holder.nama.setText(contact.getNamaLengkap());
        holder.jabatan.setText(contact.getJabatan());
        holder.penempatan.setText(contact.getPenempatan());
        holder.email.setText(contact.getEmail());

        return convertView;
    }

    static class viewHolder{
        TextView nama, jabatan, penempatan, email;
        CircleImageView image;
    }
}
