package com.phlx.anchorcollect.ui.fragment.search.adapter;

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

import androidx.recyclerview.widget.RecyclerView;


import com.phlx.anchorcollect.R;
import com.phlx.anchorcollect.entity.DictEntity;
import com.phlx.anchorcollect.ui.fragment.search.interf.IOnFrozenSemenItemClickListener;

import java.util.ArrayList;

public class FrozenSemenAdapter extends RecyclerView.Adapter<FrozenSemenAdapter.MyViewHolder> implements View.OnClickListener{

    private Context context;

    private ArrayList<DictEntity> frozenSemens = new ArrayList<>();

    public FrozenSemenAdapter(Context context, ArrayList<DictEntity> list) {
        this.context = context;
        this.frozenSemens = list;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).
                inflate(R.layout.item_search, parent, false);
        MyViewHolder holder = new MyViewHolder(view);
        view.setOnClickListener(this);
        return holder;
    }

    @Override
    public void onBindViewHolder(final MyViewHolder holder, final int position) {
        holder.name.setText(frozenSemens.get(position).getDictLabel());
//        holder.phone.setText(frozenSemens.get(position).getVeterinaryPhone());
        holder.itemView.setTag(position);
    }

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

    @Override
    public void onClick(View v) {
        if (onFrozenSemenItemClickListener != null && frozenSemens.size() > 0) {
            onFrozenSemenItemClickListener.onItemClick(frozenSemens.get((Integer) v.getTag()));
        }
    }

    class MyViewHolder extends RecyclerView.ViewHolder {

        TextView name;
//        TextView phone;

        public MyViewHolder(View view) {
            super(view);
            name = (TextView) view.findViewById(R.id.name_tv);
//            phone = (TextView) view.findViewById(R.id.phone_tv);
        }
    }

    private IOnFrozenSemenItemClickListener onFrozenSemenItemClickListener;

    public void setOnItemClickListener(IOnFrozenSemenItemClickListener onFrozenSemenItemClickListener) {
        this.onFrozenSemenItemClickListener = onFrozenSemenItemClickListener;
    }

}
