package com.amz.genie.adapters

import android.util.TypedValue
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import com.amz.genie.R
import com.amz.genie.models.OfficeTrnAksiKepada

class GeneralDetailPenerimaAdapter :
    ListAdapter<OfficeTrnAksiKepada, GeneralDetailPenerimaAdapter.VH>(DIFF) {

    companion object {
        private val DIFF = object : DiffUtil.ItemCallback<OfficeTrnAksiKepada>() {
            override fun areItemsTheSame(oldItem: OfficeTrnAksiKepada, newItem: OfficeTrnAksiKepada): Boolean {
                return oldItem.id == newItem.id
            }

            override fun areContentsTheSame(oldItem: OfficeTrnAksiKepada, newItem: OfficeTrnAksiKepada): Boolean {
                return oldItem == newItem
            }
        }
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): VH {
        val v = LayoutInflater.from(parent.context)
            .inflate(R.layout.item_inbox_detail_penerima, parent, false)
        return VH(v)
    }

    override fun onBindViewHolder(holder: VH, position: Int) {
        holder.bind(getItem(position))
    }

    class VH(itemView: View) : RecyclerView.ViewHolder(itemView) {
        private val tv: TextView = itemView.findViewById(R.id.tv_penerima_item)

        fun bind(item: OfficeTrnAksiKepada) {
            val nama = item.kepada.nama
            tv.text = nama
            tv.setBackgroundResource(R.drawable.bg_chip_penerima_dark_green)
            tv.setTextColor(itemView.context.getColor(R.color.colorWhitePure))

            val px = itemView.resources.getDimension(R.dimen.font_size_nano) // sudah px
            tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, px)
        }
    }
}
