package es.verdnatura.presentation.view.feature.delivery.adapters

import android.os.Build
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.annotation.RequiresApi
import androidx.recyclerview.widget.RecyclerView
import es.verdnatura.databinding.ItemExpeditionlogRowBinding
import es.verdnatura.presentation.view.feature.delivery.model.ExpeditionInfoLog


class ExpeditionLogAdapter(
    private val items: List<ExpeditionInfoLog>
) : RecyclerView.Adapter<ExpeditionLogAdapter.ItemHolder>() {


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

    override fun getItemCount() = items.size

    @RequiresApi(Build.VERSION_CODES.O)
    override fun onBindViewHolder(holder: ItemHolder, position: Int) {
        holder.bind(items[position])
    }

    inner class ItemHolder(
        val binding: ItemExpeditionlogRowBinding
    ) : RecyclerView.ViewHolder(binding.root) {
        private val res = binding.root.context.resources
        @RequiresApi(Build.VERSION_CODES.O)
        fun bind(item: ExpeditionInfoLog) {
            binding.apply {
                this.item = item
            }
        }
    }
}
