package com.gh.gamecenter.forum.home.follow.viewholder

import androidx.recyclerview.widget.RecyclerView.ViewHolder
import com.gh.gamecenter.common.entity.LinkEntity
import com.gh.gamecenter.common.utils.toColor
import com.gh.gamecenter.databinding.ItemHomeRecommendListCustomBinding
import com.gh.gamecenter.entity.FollowCommonContentCollection
import com.gh.gamecenter.feature.exposure.ExposureEvent
import com.gh.gamecenter.home.custom.model.CustomPageData
import com.gh.gamecenter.home.custom.ui.CommonContentRecommendUi

/**
 * 通用内容合集-金刚区
 * 首页推荐入口
 */

class FollowHomeRecommendItemViewHolder(
    val binding: ItemHomeRecommendListCustomBinding,
    private val listener: OnChildEventListener
) : ViewHolder(binding.root) {

    private lateinit var data: FollowCommonContentCollection

    private val recommendUi by lazy {
        CommonContentRecommendUi(binding, object : CommonContentRecommendUi.OnRecommendListener {
            override fun navigateToLinkPage(link: LinkEntity, text: String, exposureEvent: ExposureEvent?) {
                listener.navigateToLinkPage(
                    bindingAdapterPosition,
                    link,
                    data.linkCommonCollection,
                    text,
                    exposureEvent
                )
            }

        })
    }

    fun bindView(data: FollowCommonContentCollection) {
        this.data = data
        val recommends = data.linkCommonCollection.recommends
        recommendUi.bind(recommends, listOf())
        itemView.setBackgroundColor(com.gh.gamecenter.common.R.color.ui_surface.toColor(itemView.context))
    }

    companion object {
        //图标最多列数
        private const val MAX_SPAN_COUNT = 5
    }

    interface OnChildEventListener {

        fun navigateToLinkPage(
            position: Int,
            link: LinkEntity,
            data: CustomPageData.CommonContentCollection,
            text: String,
            exposureEvent: ExposureEvent?
        )
    }
}