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

import android.widget.FrameLayout
import android.widget.ImageView
import coil.load
import coil.transform.RoundedCornersTransformation
import com.zhpan.bannerview.BaseBannerAdapter
import com.zhpan.bannerview.BaseViewHolder
import kr.co.vividnext.sodalive.R
import kr.co.vividnext.sodalive.extensions.dpToPx

class AudioContentMainBannerAdapter(
    private val itemWidth: Int,
    private val itemHeight: Int,
    private val onClick: (GetAudioContentBannerResponse) -> Unit
) : BaseBannerAdapter<GetAudioContentBannerResponse>() {
    override fun bindData(
        holder: BaseViewHolder<GetAudioContentBannerResponse>,
        data: GetAudioContentBannerResponse,
        position: Int,
        pageSize: Int
    ) {
        val ivBanner = holder.findViewById<ImageView>(R.id.iv_recommend_live)
        val layoutParams = ivBanner.layoutParams as FrameLayout.LayoutParams

        layoutParams.width = itemWidth
        layoutParams.height = itemHeight

        ivBanner.load(data.thumbnailImageUrl) {
            crossfade(true)
            placeholder(R.drawable.ic_logo)
            transformations(RoundedCornersTransformation(5.3f.dpToPx()))
        }
        ivBanner.layoutParams = layoutParams
        ivBanner.setOnClickListener { onClick(data) }
    }

    override fun getLayoutId(viewType: Int): Int {
        return R.layout.item_recommend_live
    }
}
