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

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.content.ContentProviderCompat.requireContext
import androidx.recyclerview.widget.RecyclerView
import es.verdnatura.databinding.ItemInventaryRowBinding
import es.verdnatura.databinding.ItemWorkermistakeRowBinding
import es.verdnatura.domain.toast
import es.verdnatura.presentation.common.OnInvetoryNichoClickListener
import es.verdnatura.presentation.common.OnPasillerosItemClickListener
import es.verdnatura.presentation.common.onMistakeWorkerClickListener
import es.verdnatura.presentation.view.feature.inventario.model.ItemInventaryVO
import es.verdnatura.presentation.view.feature.pasillero.model.PasillerosItemVO
import es.verdnatura.presentation.view.feature.workermistake.model.WorkerFromMistake
import timber.log.Timber.d


class WorkermistakeAdapter  (
    private val items: List<WorkerFromMistake>,
    private val onMistakeWorkerClickListener: onMistakeWorkerClickListener
        //private val onPasillerosItemClickListener: OnPasillerosItemClickListener*/
    ): RecyclerView.Adapter<WorkermistakeAdapter.ItemHolder> () {


        override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemHolder {
            return ItemHolder(
                ItemWorkermistakeRowBinding.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: ItemWorkermistakeRowBinding
        ) : RecyclerView.ViewHolder(binding.root){
            private val res = binding.root.context.resources
            fun bind(item: WorkerFromMistake) {
                binding.apply {
                    this.item = item

                        itemFirstname.visibility = View.VISIBLE
                        itemLastname.visibility = View.VISIBLE
                    }
                   /* itemNicho.setOnClickListener {
                        onInvetoryNichoClickListener.onInvetoryNichoClickListener(item)
                    }
                    itemFk.setOnClickListener {
                        onPasillerosItemClickListener.onPasillerosItemClickListener(PasillerosItemVO(title = "Consultar artículo"),item.itemFk)
                    }
                    itemUp.setOnClickListener {
                        onPasillerosItemClickListener.onPasillerosItemClickListener(PasillerosItemVO(title = "Buscar item"),item.itemFk)
                    }
                    itemDown.setOnClickListener {
                        onPasillerosItemClickListener.onPasillerosItemClickListener(PasillerosItemVO(title = "Buscar item"),item.itemFk)
                    }*/

                    binding.imageErrorMessage.setOnClickListener {
                    d("test_imageError")
                    onMistakeWorkerClickListener.onMistakeWorkerClickListener(item)
                    //false
                }
                }
            }

}
