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


import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import es.verdnatura.R
import es.verdnatura.databinding.ItemShelvinglogRowBinding
import es.verdnatura.presentation.common.OnPasillerosItemClickListener
import es.verdnatura.presentation.view.feature.historicoshelving.model.ItemShelvingLog
import es.verdnatura.presentation.view.feature.pasillero.model.PasillerosItemVO

class ItemShelvingLogAdapter(
    private val items: List<ItemShelvingLog>,
    private val onPasillerosItemClickListener: OnPasillerosItemClickListener
) : RecyclerView.Adapter<ItemShelvingLogAdapter.ItemHolder>() {


    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemHolder {
        return ItemHolder(
            ItemShelvinglogRowBinding.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 {

            val shelvingFk = items[position].shelvingFk
            if (!shelvingFk.isNullOrEmpty()) {
                onPasillerosItemClickListener.onPasillerosItemClickListener(
                    PasillerosItemVO(
                        title = holder.binding.root.context.getString(
                            R.string.titleUbicator
                        )
                    ), shelvingFk
                )
            }

        }
    }

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

            }
        }
    }
}
