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

import android.content.Intent
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.TransaksiItem
import com.proyek.akhir.kodel.ui.koperasi.berita.detailBerita.AddBeritaKoperasiActivity
import kotlinx.android.synthetic.main.item_history.view.*


class HistoryKoperasiAdapter(private val listHistory: List<TransaksiItem>) :
    RecyclerView.Adapter<HistoryKoperasiAdapter.HistoryViewHolder>() {

    inner class HistoryViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        fun bind(history: TransaksiItem) {
            with(itemView) {
                itemView.setOnClickListener {
                    textView4.text =
                        context.getString(R.string.pengisian_saldo_sebesar_x, history.jlhSaldo.toString())
                    context.startActivity(
                        Intent(
                            this.context,
                            AddBeritaKoperasiActivity::class.java
                        )
                    )
                }
            }
        }
    }

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

    override fun getItemCount(): Int = listHistory.size

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