package com.proyek.akhir.kodel.ui.koperasi.beranda.tariksaldo

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.proyek.akhir.kodel.R
import com.proyek.akhir.kodel.data.response.TarikSaldoItem
import kotlinx.android.synthetic.main.item_tarik_saldo.view.*

class TarikSaldoAdapter(private val listTarikSaldo: List<TarikSaldoItem>) :
    RecyclerView.Adapter<TarikSaldoAdapter.TarikSaldoViewHolder>() {

    inner class TarikSaldoViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        fun bind(item: TarikSaldoItem) {
            with(itemView) {
                namePenggunaTarikSaldo.text = item.namaPengguna
                jlhTarikSaldo.text =
                    context.getString(R.string.penarikan_x, item.jlhSaldo.toString())
            }
        }

    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TarikSaldoViewHolder =
        TarikSaldoViewHolder(
            LayoutInflater.from(parent.context).inflate(
                R.layout.item_tarik_saldo, parent, false
            )
        )

    override fun getItemCount(): Int = listTarikSaldo.size

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