package es.verdnatura.presentation.view.feature.delivery.adapters

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.core.content.ContextCompat.getColor
import androidx.recyclerview.widget.RecyclerView
import es.verdnatura.R
import es.verdnatura.databinding.ItemExpeditionLoadunloadRowBinding
import es.verdnatura.presentation.common.OnItemCardRowClickListener
import es.verdnatura.presentation.view.feature.delivery.model.ExpeditionInfoLoadUnload


class ExpeditionLoadUnloadAdapter(
    private val items: List<ExpeditionInfoLoadUnload>,

) : RecyclerView.Adapter<ExpeditionLoadUnloadAdapter.ItemHolder>() {


    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemHolder {
        return ItemHolder(
            ItemExpeditionLoadunloadRowBinding.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: ItemExpeditionLoadunloadRowBinding
    ) : RecyclerView.ViewHolder(binding.root) {
        private val res = binding.root.context.resources
        fun bind(item: ExpeditionInfoLoadUnload) {
            binding.apply {
                when (item.code) {
                    "ON DELIVERY" -> {
                        expeditionView.setBackgroundColor(
                            getColor(expeditionView.context, R.color.verdnatura_pumpkin_orange)
                        )
                    }
                    "DELIVERED" -> expeditionView.setBackgroundColor(
                        getColor(expeditionView.context, R.color.verdnatura_dark_mint)
                    )

                    "PALLETIZED" -> expeditionView.setBackgroundColor(
                        getColor(expeditionView.context, R.color.verdnatura_black_5)
                    )
                    else -> {
                        expeditionView.setBackgroundColor(
                            getColor(expeditionView.context, R.color.verdnatura_black_5)
                        )

                    }
                }


                this.item = item
            }
        }
    }
}
