package com.ar.drawing.assistant.paint.tooladapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

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

import com.ar.drawing.assistant.paint.databinding.ItChildBinding;
import com.ar.drawing.assistant.paint.toollistener.OnClickCallback;
import com.ar.drawing.assistant.paint.utils.Common;

import java.util.List;

public class AdChild extends RecyclerView.Adapter<AdChild.ChildVH> {


    private Context mCon;
    private List<String> data;

    private OnClickCallback listener;


    public void setListener(OnClickCallback listener) {
        this.listener = listener;
    }

    public AdChild(Context mCon, List<String> bitmapList ) {
        this.mCon = mCon;
        data = bitmapList;

    }


    @NonNull
    @Override
    public ChildVH onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

        ItChildBinding inflate = ItChildBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);
        return new ChildVH(inflate);
    }

    @Override
    public void onBindViewHolder(@NonNull ChildVH holder, int position) {

        String name = data.get(position);
        Bitmap bitmap = Common.loadImageFromAssets(mCon, name);
        holder.binding.imPreview.setImageBitmap(bitmap);
        holder.binding.cardView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener != null) {
                    listener.onClickItem(1, name);
                }
            }
        });



    }

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

    public static class ChildVH extends RecyclerView.ViewHolder {


        private ItChildBinding binding;


        public ChildVH(@NonNull ItChildBinding itemView) {
            super(itemView.getRoot());
            binding = itemView;
        }


    }
}
