package com.sambath.kunkhmer.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.sambath.kunkhmer.R
import com.squareup.picasso.Picasso

class LivesAdapter(private val cardList: List<LivesCardItem>) : RecyclerView.Adapter<LivesAdapter.ViewHolder>() {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): LivesAdapter.ViewHolder {
        val itemView = LayoutInflater.from(parent.context).inflate(R.layout.layout_lives_item_card, parent, false)
        return LivesAdapter.ViewHolder(itemView)
    }

    override fun onBindViewHolder(holder: LivesAdapter.ViewHolder, position: Int) {
        val currentItem = cardList[position]

        Picasso.get().load(currentItem.imageResource).into(holder.imageView)
        holder.subTitleTextView.text = currentItem.subTitle
        holder.titleTextView.text = currentItem.title
    }

    override fun getItemCount() = cardList.size

    class ViewHolder(ItemView: View) : RecyclerView.ViewHolder(ItemView) {
        val imageView: ImageView = itemView.findViewById(R.id.imageView)
        val subTitleTextView: TextView = itemView.findViewById(R.id.subTitleTextView)
        val titleTextView: TextView = itemView.findViewById(R.id.titleTextView)
    }
}