package com.gh.gamecenter.gamedetail.detail.viewholder

import com.gh.common.util.DirectUtils
import com.gh.gamecenter.common.utils.SensorsBridge
import com.gh.gamecenter.common.utils.display
import com.gh.gamecenter.common.utils.toColor
import com.gh.gamecenter.common.utils.updateRoundingParams
import com.gh.gamecenter.databinding.ItemGameDetailRecommendImageBinding
import com.gh.gamecenter.feature.view.DownloadButton
import com.gh.gamecenter.gamedetail.GameDetailViewModel
import com.gh.gamecenter.gamedetail.entity.GameDetailData

class GameDetailRecommendImageItemViewHolder(
    val binding: ItemGameDetailRecommendImageBinding,
    downloadBtn: DownloadButton?,
    viewModel: GameDetailViewModel
) : BaseGameDetailItemViewHolder(binding.root, downloadBtn, viewModel) {
    override fun bindView(data: GameDetailData) {
        super.bindView(data)
        val entity = data.linkImageRecommend ?: return
        binding.run {
            titleTv.setTextColor(com.gh.gamecenter.common.R.color.text_primary.toColor(context))
            imageIv.updateRoundingParams {
                setOverlayColor(com.gh.gamecenter.common.R.color.ui_surface.toColor(context))
            }
            titleTv.text = entity.title
            imageIv.display(entity.img)
            root.setOnClickListener { _ ->
                entity.link?.let {
                    DirectUtils.directToLinkPage(
                        context = context,
                        linkEntity = it,
                        entrance = viewModel.entrance ?: "",
                        path = "游戏详情"
                    )
                    SensorsBridge.trackGameDetailModuleClick(
                        gameId,
                        gameName,
                        gameType,
                        "组件内容",
                        moduleType,
                        entity.title,
                        sequence,
                        null,
                        null,
                        it.type,
                        it.link,
                        it.link,
                        gameStatus
                    )
                }
            }
        }
    }
}