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


import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import es.verdnatura.R
import es.verdnatura.databinding.ItemShelvinglogRowBinding
import es.verdnatura.presentation.view.feature.historicoshelving.model.ItemShelvingLog
import java.text.SimpleDateFormat
import java.util.*

class ItemShelvingLogAdapter  (
    private val items: List<ItemShelvingLog>
                        ): 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])
    }

    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
                /* val sdf = SimpleDateFormat("yyyy-MM-dd")
                 val currentDate = sdf.format(Date())
                 if (currentDate == item.created){
                     saledate.setBackgroundColor(
                         ContextCompat.getColor(historicoDate.context,
                             R.color.verdnatura_pumpkin_orange))
                 }else{
                     saledate.setBackgroundColor(
                         ContextCompat.getColor(historicoDate.context,
                             R.color.verdnatura_black_5))
                 }*/
            }
        }
    }
}
