package kr.co.vividnext.sodalive.audio_content.main

import android.annotation.SuppressLint
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import kr.co.vividnext.sodalive.databinding.ItemAudioContentMainBinding

class AudioContentMainContentAdapter(
    private val onClickItem: (Long) -> Unit,
    private val onClickCreator: (Long) -> Unit,
) : RecyclerView.Adapter<AudioContentMainItemViewHolder>() {

    private val items = mutableListOf<GetAudioContentMainItem>()

    override fun onCreateViewHolder(
        parent: ViewGroup,
        viewType: Int
    ) = AudioContentMainItemViewHolder(
        ItemAudioContentMainBinding.inflate(
            LayoutInflater.from(parent.context),
            parent,
            false
        ),
        onClickItem = onClickItem,
        onClickCreator = onClickCreator
    )

    override fun getItemCount() = items.size

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

    @SuppressLint("NotifyDataSetChanged")
    fun addItems(items: List<GetAudioContentMainItem>) {
        this.items.clear()
        this.items.addAll(items)
        notifyDataSetChanged()
    }
}
