package com.proyek.akhir.kodel.ui.koperasi.kupon

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.KuponItem
import com.proyek.akhir.kodel.utils.DateConverter
import kotlinx.android.synthetic.main.item_kupon_koperasi.view.*

class KuponAdapter(private val listKupon: List<KuponItem>) :
    RecyclerView.Adapter<KuponAdapter.KuponViewHolder>() {
    inner class KuponViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        fun bind(kupon: KuponItem) {
            with(itemView) {
                judulKupon.text = kupon.desckupon
                codeKupon.text = kupon.codekupon
                tglKupon.text = DateConverter().dateKuponConverter(kupon.validity)
            }
        }
    }

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

    override fun getItemCount(): Int = listKupon.size

    override fun onBindViewHolder(holder: KuponAdapter.KuponViewHolder, position: Int) {
        holder.bind(listKupon[position])
    }
}