package com.navinfo.outdoor.adapter;

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

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

import com.navinfo.outdoor.R;
import com.navinfo.outdoor.bean.TaskExplainInfo;
import com.navinfo.outdoor.bean.TaskPrefectureBean;

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

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

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

    public void setExplainList(List<TaskPrefectureBean.BodyBean.ListBean> explainList) {
        this.issueList.addAll(explainList);
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        final View issueItem = LayoutInflater.from(context).inflate(R.layout.issue_problem_item, parent, false);

        return new ViewHolder(issueItem);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        holder.tvIssue.setText(issueList.get(position).getTitle());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onIssueClick != null) {
                    onIssueClick.onClick(position);
                }
            }
        });
    }

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

    class ViewHolder extends RecyclerView.ViewHolder {
        TextView tvIssue;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            tvIssue = itemView.findViewById(R.id.tv_issue_title);
        }
    }

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

    private OnIssueClick onIssueClick;

    public void setOnIssueClick(OnIssueClick onIssueClick) {
        this.onIssueClick = onIssueClick;
    }
}
