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

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import es.verdnatura.databinding.ItemWorkFormsRowBinding
import es.verdnatura.presentation.common.OnTrashItemRowClickListener
import es.verdnatura.presentation.common.OnWorkFormsItemRowClickListener
import es.verdnatura.presentation.view.feature.login.model.WorkForms

class WorkFormAdapter(
    private val items: List<WorkForms>,
    private val OnWorkFormsItemRowClickListener: OnWorkFormsItemRowClickListener,
    private val OnTrashItemRowClickListener: OnTrashItemRowClickListener
    //  private var showDelete: Boolean = false
) : RecyclerView.Adapter<WorkFormAdapter.ItemHolder>() {


    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemHolder {
        return ItemHolder(
            ItemWorkFormsRowBinding.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 {
            OnWorkFormsItemRowClickListener.OnWorkFormsItemRowClickListener(items[position])
        }
        holder.binding.itemImage.setOnClickListener{
            OnTrashItemRowClickListener.OnTrashItemRowClickListener(items[position])
        }

    }


    inner class ItemHolder(
        val binding: ItemWorkFormsRowBinding
    ) : RecyclerView.ViewHolder(binding.root) {
        //private val res = binding.root.context.resources
        fun bind(item: WorkForms) {
            binding.apply {
                this.item = item
                if (item.isShowDelete) {
                    itemImage.visibility = View.VISIBLE
                }
                else itemImage.visibility = View.GONE

                itemImage.setOnClickListener{
                    //deleteWorkForm(item.name)
                }
                //itemCode.visibility = View.GONE
            }
        }
    }

}
