package com.gh.gamecenter.home.test_v2

import androidx.core.content.ContextCompat
import com.gh.common.util.DirectUtils
import com.gh.common.util.NewFlatLogUtils
import com.gh.gamecenter.R
import com.gh.gamecenter.common.base.BaseRecyclerViewHolder
import com.gh.gamecenter.common.utils.setDebouncedClickListener
import com.gh.gamecenter.common.utils.toColor
import com.gh.gamecenter.databinding.ItemHomeGameTestV2RecommendLabelBinding
import com.gh.gamecenter.entity.RecommendLabel
import com.gh.gamecenter.entity.SubjectRecommendEntity

/**
 * @author : liujiarui
 * date : 2023/3/3
 * description : 新游开测 推荐标签 holder
 */
class HomeGameTestV2RecommendViewHolder(
    private val mBinding: ItemHomeGameTestV2RecommendLabelBinding,
    private val mLocation: String,
    private val mBlockData: SubjectRecommendEntity? = null
) : BaseRecyclerViewHolder<Any>(mBinding.root) {
    fun bind(data: RecommendLabel) {
        val context = mBinding.tvLabel.context
        mBinding.tvLabel.text = data.text
        mBinding.tvLabel.setTextColor(com.gh.gamecenter.common.R.color.text_secondary.toColor(context))
        mBinding.tvLabel.background =
            ContextCompat.getDrawable(
                context,
                R.drawable.bg_game_test_v2_recommend_label
            )
        mBinding.tvLabel.setDebouncedClickListener {
            DirectUtils.directToLinkPage(
                context,
                data.link,
                "新游开测",
                ""
            )
            //埋点上报
            NewFlatLogUtils.logGameTestV2RecommendLabelClick(
                location = mLocation,
                blockId = mBlockData?.link ?: "",
                blockName = mBlockData?.name ?: "",
                tagId = data.id,
                text = data.text,
                sequence = this.bindingAdapterPosition,
                linkType = data.link.type ?: "",
                linkId = data.link.link ?: "",
                linkText = data.link.text ?: ""
            )
        }
    }
}