package com.kaixed.kchat.view.adapter;

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

import androidx.annotation.NonNull;
import androidx.constraintlayout.helper.widget.Layer;
import androidx.recyclerview.widget.RecyclerView;

import com.kaixed.kchat.R;
import com.kaixed.kchat.view.i.OnItemClickListener;

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

/**
 * @Author: kaixed
 * @Date: 2024/5/30 16:51
 * @Description: TODO
 */
public class EmojiAdapter extends RecyclerView.Adapter<EmojiAdapter.MyViewHolder> {

    private final List<String> strings;
    private OnItemClickListener onItemClickListener;

    public EmojiAdapter(List<String> strings) {
        this.strings = strings;
    }

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

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.emoji_recycle_item, parent, false);

        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, @SuppressLint("RecyclerView") int position) {
        holder.itemView.setOnClickListener(v -> {
            onItemClickListener.onItemClick(position);
        });
    }

    @Override
    public int getItemCount() {
        return strings.isEmpty() ? 0 : strings.size();
    }

    public static class MyViewHolder extends RecyclerView.ViewHolder {
        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
        }

    }
}
