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

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import es.verdnatura.databinding.ItemWorkermistakeRowBinding
import es.verdnatura.presentation.common.OnMistakeWorkerClickListener
import es.verdnatura.presentation.view.feature.workermistake.model.WorkerFromMistake


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
            }

            binding.imageErrorMessage.setOnClickListener {
                onMistakeWorkerClickListener.onMistakeWorkerClickListener(item)
            }
        }
    }

}
