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

import androidx.recyclerview.widget.RecyclerView
import coil.load
import coil.transform.CircleCropTransformation
import coil.transform.RoundedCornersTransformation
import kr.co.vividnext.sodalive.R
import kr.co.vividnext.sodalive.databinding.ItemAudioContentMainBinding
import kr.co.vividnext.sodalive.extensions.dpToPx

class AudioContentMainItemViewHolder(
    private val binding: ItemAudioContentMainBinding,
    private val onClickItem: (Long) -> Unit,
    private val onClickCreator: (Long) -> Unit
) : RecyclerView.ViewHolder(binding.root) {
    fun bind(item: GetAudioContentMainItem) {
        binding.ivAudioContentCoverImage.load(item.coverImageUrl) {
            crossfade(true)
            placeholder(R.drawable.ic_place_holder)
            transformations(RoundedCornersTransformation(2.7f.dpToPx()))
        }

        binding.ivAudioContentCreator.load(item.creatorProfileImageUrl) {
            crossfade(true)
            placeholder(R.drawable.ic_place_holder)
            transformations(CircleCropTransformation())
        }

        binding.tvAudioContentTitle.text = item.title
        binding.tvAudioContentCreatorNickname.text = item.creatorNickname

        binding.ivAudioContentCreator.setOnClickListener { onClickCreator(item.creatorId) }
        binding.root.setOnClickListener { onClickItem(item.contentId) }
    }
}
