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

class EventAdapter(private val cardList: List<EventCardItem>) : RecyclerView.Adapter<EventAdapter.ViewHolder>() {

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

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

        holder.imageView.setImageResource(currentItem.imageResource)
        holder.subTitleTextView.text = currentItem.subTitle
        holder.titleTextView.text = currentItem.title
        holder.dateTitleTextView.text = currentItem.dateTitle
    }

    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)
        val dateTitleTextView: TextView = itemView.findViewById(R.id.dateTitleTextView)
    }
}