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


    import android.content.Context
    import android.view.LayoutInflater
    import android.view.ViewGroup
    import androidx.recyclerview.widget.RecyclerView
    import es.verdnatura.R
    import es.verdnatura.databinding.ItemPlacementReubicationRowBinding
    import es.verdnatura.databinding.ItemPlacementRowBinding
    import es.verdnatura.presentation.common.OnPasillerosItemClickListener
    import es.verdnatura.presentation.view.feature.pasillero.model.PasillerosItemVO
    import es.verdnatura.presentation.view.feature.reubication.model.PlacementReubication
    import es.verdnatura.presentation.view.feature.sacador.model.PlacementVO

    class ReubicatorPlacementAdapter (
        private val items: List<PlacementReubication>,
        private val onPasillerosItemClickListener: OnPasillerosItemClickListener
    ): RecyclerView.Adapter<ReubicatorPlacementAdapter.AjustesItemHolder> () {
        var context: Context? = null
        override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): AjustesItemHolder {
            this.context = parent.context
            return AjustesItemHolder(
                ItemPlacementReubicationRowBinding.inflate(LayoutInflater.from(parent.context),parent,false)
            )
        }

        override fun getItemCount() =items.size

        override fun onBindViewHolder(holder: AjustesItemHolder, position: Int) {
            holder.bind(items[position])
        }

        inner class AjustesItemHolder(
            val binding: ItemPlacementReubicationRowBinding
        ) : RecyclerView.ViewHolder(binding.root){
            fun bind(placement: PlacementReubication) {
                binding.apply {
                    if (placement.plate.isNullOrEmpty())
                        placement.plate = ""//placement.parking
                    if (placement.visible.isNullOrEmpty())
                        placement.visible = "("+placement.visible+")"
                    this.item = placement

                    itemRootLayout.setOnClickListener {
                        onPasillerosItemClickListener.onPasillerosItemClickListener(
                            PasillerosItemVO(title = binding.root.context.getString(
                            R.string.titleUbicator)),placement.plate)
                    }
                }
            }
        }
    }