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

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import es.verdnatura.databinding.ItemCollectionRowBinding
import es.verdnatura.databinding.ItemCollectionRowNewBinding
import es.verdnatura.presentation.common.OnCollectionSelectedListener
import es.verdnatura.presentation.common.OnCollectionTicketSelectedListener
import es.verdnatura.presentation.view.feature.sacador.model.CollectionTicket
import es.verdnatura.presentation.view.feature.sacador.model.CollectionVO

class CollectionAdapterNew(
    private val items: List<CollectionTicket>,
    private val onCollectionTicketSelected: OnCollectionTicketSelectedListener,
    private val type: String
) : RecyclerView.Adapter<CollectionAdapterNew.AjustesItemHolder>() {


    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): AjustesItemHolder {
        return AjustesItemHolder(
            ItemCollectionRowNewBinding.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 {
            onCollectionTicketSelected.onCollectionSelected(items[position], type)
        }
    }


    class AjustesItemHolder(
        val binding: ItemCollectionRowNewBinding
    ) : RecyclerView.ViewHolder(binding.root) {
        fun bind(item: CollectionTicket) {
            binding.apply {
                if (item.ticketTotalCount == null) {
                    binding.totalTicketsId.visibility = View.GONE
                }
                this.item = item
            }
        }
    }
}