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

import android.util.Log
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import es.verdnatura.databinding.ItemExpeditiontruckRowBinding
import es.verdnatura.presentation.common.OnTruckClickListener
import es.verdnatura.presentation.view.feature.paletizador.model.ItemExpeditionTruckVO

class ExpeditionListAdapter (
    private val items: List<ItemExpeditionTruckVO>,
    private val onTruckClickListener: OnTruckClickListener
): RecyclerView.Adapter<ExpeditionListAdapter.ItemHolder> () {


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

    override fun getItemCount() =items.size

    override fun onBindViewHolder(holder: ItemHolder, position: Int) {
        holder.bind(items[position])
        holder.binding.root.setOnClickListener {
            onTruckClickListener.onTruckClickListener(items[position],"")
            ////Log.i("VERDNATURA:","3-ontruckClickListener")
        }
    }

    inner class ItemHolder(
        val binding: ItemExpeditiontruckRowBinding
    ) : RecyclerView.ViewHolder(binding.root){
        private val res = binding.root.context.resources
        fun bind(item: ItemExpeditionTruckVO) {
            binding.apply {
                this.item = item
            }
        }
    }
}