package kr.co.vividnext.sodalive.live.recommend

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 RecommendLiveAdapter(
    private val itemWidth: Int,
    private val itemHeight: Int,
    private val onClick: (Long) -> Unit
) : BaseBannerAdapter<GetRecommendLiveResponse>() {
    override fun bindData(
        holder: BaseViewHolder<GetRecommendLiveResponse>,
        data: GetRecommendLiveResponse,
        position: Int,
        pageSize: Int
    ) {
        val ivRecommendLive = holder.findViewById<ImageView>(R.id.iv_recommend_live)
        val layoutParams = ivRecommendLive.layoutParams as FrameLayout.LayoutParams

        layoutParams.width = itemWidth
        layoutParams.height = itemHeight

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

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