package cz.muni.sutralog.ui.list

import android.view.LayoutInflater
import android.view.ViewGroup
import android.widget.Filter
import android.widget.Filterable
import android.widget.Toast
import androidx.lifecycle.LiveData
import androidx.recyclerview.widget.RecyclerView
import cz.muni.sutralog.databinding.RockItemListBinding
import cz.muni.sutralog.data.RockPresentableListItem

class RockAdapter(
    private val onItemClick: (RockPresentableListItem) -> Unit,
    private val onItemLongClick: (RockPresentableListItem) -> Boolean,
) : RecyclerView.Adapter<RockViewHolder>() {

    private var listItems: MutableList<RockPresentableListItem> = mutableListOf()

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RockViewHolder {
        val binding = RockItemListBinding.inflate(LayoutInflater.from(parent.context), parent, false)
        return RockViewHolder(binding)
    }

    override fun onBindViewHolder(holder: RockViewHolder, position: Int) {
        holder.bind(listItems[position], onItemClick, onItemLongClick)
    }

    fun submitList(newListItems: List<RockPresentableListItem>) {
        listItems = newListItems.toMutableList()
        notifyDataSetChanged()
    }

    fun removeItem(position: Int) {
        listItems.removeAt(position)
        notifyItemRemoved(position)
    }

    override fun getItemCount(): Int = listItems.size
}
