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.TaskExplainBean;
import com.navinfo.outdoor.bean.TaskPrefectureBean;

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

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

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

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

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

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

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


    class ViewHolder extends RecyclerView.ViewHolder {
        ImageView ivCapacity;
        TextView tvCapacity;
        TextView tvResults;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            ivCapacity = itemView.findViewById(R.id.iv_tas_capacity);
            tvCapacity = itemView.findViewById(R.id.tas_capacity_title);
            tvResults = itemView.findViewById(R.id.tv_capacity_through);
        }

    }

    public interface OnCapacityClick {
        void onClick(int pos);
    }

    private OnCapacityClick onCapacityClick;

    public void setOnCapacityClick(OnCapacityClick onCapacityClick) {
        this.onCapacityClick = onCapacityClick;
    }
}
