package es.verdnatura.presentation.common

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import es.verdnatura.databinding.ItemGeneralRowBinding

class GeneralAdapter(
        private val items: List<GeneralItem>,
        private val OnGeneralItemRowClickListener: OnGeneralItemRowClickListener,
      //  private var showDelete: Boolean = false
    ): RecyclerView.Adapter<GeneralAdapter.ItemHolder> () {


        override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemHolder {
            return ItemHolder(
                ItemGeneralRowBinding.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 {
                OnGeneralItemRowClickListener.OnGeneralItemRowClickListener(items[position])
            }

        }


        inner class ItemHolder(
            val binding: ItemGeneralRowBinding
        ) : RecyclerView.ViewHolder(binding.root){
            //private val res = binding.root.context.resources
            fun bind(item: GeneralItem) {
                binding.apply {
                    this.item = item
                    /*if (showDelete) itemImage.visibility = View.VISIBLE
                    else itemImage.visibility = View.GONE*/

                    itemCode.visibility=View.GONE
                }
            }
        }
    }
