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

import android.util.Log
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import es.verdnatura.databinding.ItemCollectionRowBinding
import es.verdnatura.domain.ConstAndValues.PREITEMPICKER

import es.verdnatura.presentation.common.OnCollectionSelectedListener
import es.verdnatura.presentation.view.feature.sacador.model.CollectionVO


    class PreCollectionAdapter  (
        private val items: List<CollectionVO>,
        private val onCollectionSelected: OnCollectionSelectedListener
    ): RecyclerView.Adapter<PreCollectionAdapter.AjustesItemHolder> () {


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

        override fun getItemCount() =items.size

        override fun onBindViewHolder(holder: AjustesItemHolder, position: Int) {
            holder.bind(items[position])
            holder.binding.root.setOnClickListener {
                onCollectionSelected.onCollectionSelected(items[position],PREITEMPICKER)
               // Log.d("VERDNATURA::","2-Click item ${items[position].collectionFk}+PREITEMPICKER")
            }
        }


        class AjustesItemHolder(
            val binding: ItemCollectionRowBinding
        ) : RecyclerView.ViewHolder(binding.root){
            fun bind(item: CollectionVO) {
                binding.apply {
                    this.item = item
                }
            }
        }
    }