package kr.co.vividnext.sodalive.live.event_banner

import android.content.Context
import android.widget.ImageView
import coil.load
import com.zhpan.bannerview.BaseBannerAdapter
import com.zhpan.bannerview.BaseViewHolder
import kr.co.vividnext.sodalive.R
import kr.co.vividnext.sodalive.settings.event.EventItem

class EventBannerAdapter(
    private val context: Context,
    private val itemClick: (EventItem) -> Unit
) : BaseBannerAdapter<EventItem>() {

    override fun bindData(
        holder: BaseViewHolder<EventItem>,
        data: EventItem,
        position: Int,
        pageSize: Int
    ) {
        val ivThumbnail = holder.findViewById<ImageView>(R.id.iv_thumbnail)
        ivThumbnail.load(data.thumbnailImageUrl) {
            crossfade(true)

            val layoutParams = ivThumbnail.layoutParams
            val screenWidth = context.resources.displayMetrics.widthPixels
            layoutParams.width = screenWidth
            layoutParams.height = (screenWidth * 300) / 1000
            ivThumbnail.layoutParams = layoutParams
        }
        ivThumbnail.setOnClickListener { itemClick(data) }
    }

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