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



import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import es.verdnatura.databinding.ShelvinglogRowBinding
import es.verdnatura.presentation.view.feature.historicoshelvinglog.model.ShelvingLog

class ShelvingLogAdapter  (
    private val items: List<ShelvingLog>
                              ): RecyclerView.Adapter<ShelvingLogAdapter.ItemHolder>() {


    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemHolder {
        return ItemHolder(
            ShelvinglogRowBinding.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: ShelvinglogRowBinding
                          ) : RecyclerView.ViewHolder(binding.root){
        private val res = binding.root.context.resources
        fun bind(item: ShelvingLog) {
            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))
                 }*/
            }
        }
    }
}
