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

import androidx.recyclerview.widget.RecyclerView.ViewHolder
import com.gh.common.util.NewLogUtils
import com.gh.gamecenter.common.entity.LinkEntity
import com.gh.gamecenter.common.utils.toColor
import com.gh.gamecenter.databinding.CommonCollection12ItemCustomBinding
import com.gh.gamecenter.entity.CommonCollectionContentEntity
import com.gh.gamecenter.feature.exposure.ExposureEvent
import com.gh.gamecenter.home.custom.model.CustomPageData
import com.gh.gamecenter.home.custom.ui.CommonContentCollection12Ui

/**
 * 关注-双列banner  双列竖式卡片 竖排图文列表
 * 通用链接合集(1-2样式)
 */
class FollowCommonCollection12ViewHolder(
    val binding: CommonCollection12ItemCustomBinding,
    private val listener: OnChildEventListener
) :
    ViewHolder(binding.root) {

    private lateinit var _data: CustomPageData.CommonContentCollection

    private val collection12Ui by lazy {
        CommonContentCollection12Ui(binding, object : CommonContentCollection12Ui.OnCollection12Listener {
            override fun onChildItemClick(childPosition: Int, contentEntity: CommonCollectionContentEntity) {

                val linkEntity = contentEntity.linkEntity
                NewLogUtils.logCommonCollectionClick(
                    _data.id,
                    _data.name,
                    "",
                    "",
                    "关注列表",
                    "关注首页",
                    linkEntity.title ?: "",
                    contentEntity.addedContent1 ?: "",
                    contentEntity.addedContent2 ?: "",
                    linkEntity.type ?: "",
                    linkEntity.text ?: "",
                    childPosition + 1
                )
                NewLogUtils.logCommonCategoryHomeContentClick(
                    contentEntity.title,
                    linkEntity.type ?: "",
                    linkEntity.link ?: "",
                    linkEntity.text ?: "",
                    _data.name,
                    _data.id,
                    "关注",
                    ""
                )

                listener.navigateToLinkPage(bindingAdapterPosition, linkEntity, _data, "内容卡片", null)
            }

            override fun navigateToCommonCollectionDetailPage(collection: CustomPageData.CommonContentCollection) {
                listener.navigateToCommonCollectionDetailPage(collection)
            }

        })
    }

    fun bind(data: CustomPageData.CommonContentCollection, leftPosition: Int) {
        _data = data
        collection12Ui.bind(data, leftPosition)
        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?
        )

        fun navigateToCommonCollectionDetailPage(data: CustomPageData.CommonContentCollection)
    }

}