package kr.co.vividnext.sodalive.settings.notice

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import kr.co.vividnext.sodalive.databinding.ItemNoticeBinding

class NoticeAdapter(
    private val onClick: (NoticeItem) -> Unit
) : RecyclerView.Adapter<NoticeAdapter.ViewHolder>() {

    val items = mutableListOf<NoticeItem>()

    inner class ViewHolder(
        private val binding: ItemNoticeBinding,
        private val onClick: (NoticeItem) -> Unit
    ) : RecyclerView.ViewHolder(binding.root) {
        fun bind(notice: NoticeItem) {
            binding.tvTitle.text = notice.title
            binding.tvDate.text = notice.date
            binding.root.setOnClickListener { onClick(notice) }
        }
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        return ViewHolder(
            ItemNoticeBinding.inflate(
                LayoutInflater.from(parent.context),
                parent,
                false
            ),
            onClick
        )
    }

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

    override fun getItemCount() = items.count()
}
