package es.verdnatura.presentation.view.feature.sacador.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import es.verdnatura.databinding.ItemLastTicketRowBinding
import es.verdnatura.presentation.common.OnCollectionSelectedListener
import es.verdnatura.presentation.view.feature.sacador.model.CollectionVO
import es.verdnatura.presentation.view.feature.sacador.model.TicketStateSalix

class TicketLastStateAdapter(
    private val items: List<TicketStateSalix>,
    private val onCollectionSelected: OnCollectionSelectedListener,
    private val type: String
) : RecyclerView.Adapter<TicketLastStateAdapter.AjustesItemHolder>() {


    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): AjustesItemHolder {
        return AjustesItemHolder(
            ItemLastTicketRowBinding.inflate(LayoutInflater.from(parent.context), parent, false)
        )
    }

    override fun getItemCount() = items.size

    override fun onBindViewHolder(holder: AjustesItemHolder, position: Int) {
        holder.bind(items[position])
        holder.binding.root.setOnClickListener {
            onCollectionSelected.onCollectionSelected(CollectionVO(items[position].ticketFk), type)
        }
    }


    class AjustesItemHolder(
        val binding: ItemLastTicketRowBinding
    ) : RecyclerView.ViewHolder(binding.root) {
        fun bind(item: TicketStateSalix) {
            binding.apply {
                this.item = item
            }
        }
    }
}