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

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import es.verdnatura.R
import es.verdnatura.databinding.ItemProposalRowBinding
import es.verdnatura.presentation.common.OnItemProposalClickListener
import es.verdnatura.presentation.common.OnPasillerosItemClickListener
import es.verdnatura.presentation.view.feature.articulo.model.ItemProposal
import es.verdnatura.presentation.view.feature.pasillero.model.PasillerosItemVO

class ItemProposalAdapter(
    private val items: List<ItemProposal>,
    // private val onInvetoryNichoClickListener: OnInvetoryNichoClickListener,//
    private val onItemProposalClickListener: OnItemProposalClickListener,
    private val onPasillerosItemClickListener: OnPasillerosItemClickListener
) : RecyclerView.Adapter<ItemProposalAdapter.ItemHolder>() {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemHolder {
        return ItemHolder(
            ItemProposalRowBinding.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: ItemProposalRowBinding
    ) : RecyclerView.ViewHolder(binding.root) {
        private val res = binding.root.context.resources
        fun bind(item: ItemProposal) {
            binding.apply {
                this.item = item
                if (item.longName.isNullOrEmpty()) {
                    itemProducer.visibility = View.GONE
                } else {
                    itemProducer.visibility = View.VISIBLE
                }
                /*  itemNicho.setOnClickListener {
                       onInvetoryNichoClickListener.onInvetoryNichoClickListener(item)
                   }*/
             /*   itemNicho.setOnClickListener {
                    onItemProposalClickListener.onItemProposalClickListener(item)
                }*/
                itemFk.setOnClickListener {
                    onPasillerosItemClickListener.onPasillerosItemClickListener(
                        PasillerosItemVO(
                            title = res.getString(R.string.itemSearch)
                        ), item.itemFk
                    )
                }
                itemUp.setOnClickListener {
                    onPasillerosItemClickListener.onPasillerosItemClickListener(
                        PasillerosItemVO(
                            title = res.getString(R.string.titleItemSearch)
                        ), item.itemFk
                    )
                }
                itemDown.setOnClickListener {
                    onPasillerosItemClickListener.onPasillerosItemClickListener(
                        PasillerosItemVO(
                            title = res.getString(R.string.titleItemSearch)
                        ), item.itemFk
                    )
                }
            }
        }
    }
}