package com.navinfo.outdoor.adapter;

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

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.bumptech.glide.request.RequestOptions;
import com.navinfo.outdoor.R;
import com.navinfo.outdoor.bean.CapacityMeasureBean;
import com.navinfo.outdoor.bean.TaskPrefectureBean;

import java.util.ArrayList;
import java.util.List;

public class CapacityItemAdapter extends RecyclerView.Adapter<CapacityItemAdapter.ViewHolder> {
    private List<TaskPrefectureBean.BodyBean.ListBean> capItemList = new ArrayList<>();
    private Context context;

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

    public void setCapItemList(List<TaskPrefectureBean.BodyBean.ListBean> capItemList) {
        this.capItemList.addAll(capItemList);
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        final View capItem = LayoutInflater.from(context).inflate(R.layout.capacity_item, parent, false);
        return new ViewHolder(capItem);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        holder.tvCapItem.setText(capItemList.get(position).getTitle());
        holder.tvReaus.setText(capItemList.get(position).getStatus()+"");
        Glide.with(context).load(capItemList.get(position).getIconurl()).apply(RequestOptions.bitmapTransform(new CircleCrop())).into(holder.ivCapItem);
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (setOnClick!=null){
                    setOnClick.onClick(position);
                }
            }
        });

    }

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

    class ViewHolder extends RecyclerView.ViewHolder {
        ImageView ivCapItem;
        TextView tvCapItem;
        TextView tvReaus;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            ivCapItem = itemView.findViewById(R.id.iv_tas_capacity);
            tvCapItem = itemView.findViewById(R.id.tas_capacity_title);
            tvReaus = itemView.findViewById(R.id.tv_capacity_through);
        }
    }
    public interface setOnClick{
        void onClick(int position);
    }

    private setOnClick setOnClick;

    public void setSetOnClick(setOnClick setOnClick) {
        this.setOnClick = setOnClick;
    }
}
