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

import android.content.Context
import android.util.Log
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import es.verdnatura.databinding.ItemExpeditionscanRowBinding
import es.verdnatura.presentation.common.OnScanLongClickListener
import es.verdnatura.presentation.view.feature.paletizador.model.ItemExpeditionScanVO

class ExpeditionScanAdapter (
    private val items: List<ItemExpeditionScanVO>,
    private val onScanLongClickListener: OnScanLongClickListener
): RecyclerView.Adapter<ExpeditionScanAdapter.ItemHolder> () {

    private var context: Context? = null
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemHolder {
        this.context = parent.context
        return ItemHolder(
            ItemExpeditionscanRowBinding.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 {
            //Tarea #4125
            Log.d("VERDNATURA::","ENtranado en las expediciones del pallet")
            onScanLongClickListener.onScanLongClickListener(items[position])
        }
    }

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