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.RecyclerNavigationCustomBinding
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.CommonContentNavigationUi

/**
 * 通用内容合集-导航栏
 */
class FollowNavigationViewHolder(
    val binding: RecyclerNavigationCustomBinding,
    private val listener: OnChildEventListener
) : ViewHolder(binding.root) {

    private lateinit var data: FollowCommonContentCollection

    private val navigationUi by lazy {
        CommonContentNavigationUi(binding, object : CommonContentNavigationUi.OnNavigationListener {
            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 navigationList = data.linkCommonCollection.navigations
        if (!navigationList.isNullOrEmpty()) {
            navigationUi.bind(navigationList, null)
        }
        itemView.setBackgroundColor(com.gh.gamecenter.common.R.color.ui_surface.toColor(itemView.context))

    }

    interface OnChildEventListener {

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