package com.zztrapp.zztrapp.ui.currency.adapter;


import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

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

import com.zztrapp.zztrapp.bean.GetTreeListBean;
import com.zztrapp.zztrapp.databinding.ItemRvFaLvFaGuiChildBinding;

import java.util.List;

/**
 * Describe 法律法规child Adapter
 * Created by Bby on 2022/6/23
 * Email bby0856@163.com
 */

public class FaLvFaGuiChildAdapter extends RecyclerView.Adapter<FaLvFaGuiChildAdapter.ItemHolder> {

    private Context mContext;
    private OnItemClickListener onItemClickListener;
    private List<GetTreeListBean.ChildrenBean> list;

    public interface OnItemClickListener {
        void onItemClick(String id);
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    public FaLvFaGuiChildAdapter(Context context) {
        this.mContext = context;
    }

    public void setData(List<GetTreeListBean.ChildrenBean> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public ItemHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        ItemRvFaLvFaGuiChildBinding binding = ItemRvFaLvFaGuiChildBinding.inflate(LayoutInflater.from(mContext), parent, false);
        return new ItemHolder(binding);
    }

    @Override
    public void onBindViewHolder(ItemHolder holder, @SuppressLint("RecyclerView") int position) {
        holder.bindings.name.setText(list.get(position).getName());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (onItemClickListener != null) {
                    onItemClickListener.onItemClick(list.get(position).getId());
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return list != null ? list.size() : 0;
    }

    static class ItemHolder extends RecyclerView.ViewHolder {
        private ItemRvFaLvFaGuiChildBinding bindings;

        public ItemHolder(ItemRvFaLvFaGuiChildBinding binding) {
            super(binding.getRoot());
            bindings = binding;
        }
    }
}