package cz.muni.sutralog.ui.list

import android.view.LayoutInflater
import android.view.ViewGroup
import android.widget.Filter
import android.widget.Filterable
import androidx.recyclerview.widget.RecyclerView
import cz.muni.sutralog.data.CategoryPresentableListItem
import cz.muni.sutralog.data.RockPresentableListItem
import cz.muni.sutralog.databinding.CategoryItemListBinding

class CategoryAdapter(private val onItemClick: (CategoryPresentableListItem) -> Unit,
                      private val onItemLongClick: (CategoryPresentableListItem) -> Boolean,
) : RecyclerView.Adapter<CategoryViewHolder>() {

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

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

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

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

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


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