package com.gh.gamecenter.home.custom.viewholder

import androidx.core.content.ContextCompat
import com.gh.common.util.DirectUtils
import com.gh.gamecenter.R
import com.gh.gamecenter.common.base.BaseRecyclerViewHolder
import com.gh.gamecenter.common.utils.SensorsBridge
import com.gh.gamecenter.common.utils.setDebouncedClickListener
import com.gh.gamecenter.common.utils.toColor
import com.gh.gamecenter.databinding.ItemHomeGameTestV2RecommendLabelCustomBinding
import com.gh.gamecenter.entity.RecommendLabel
import com.gh.gamecenter.feature.entity.PageLocation

/**
 * @author : liujiarui
 * date : 2023/3/3
 * description : 新游开测 推荐标签 holder
 */
class CustomHomeGameTestV2RecommendViewHolder(
    private val mBinding: ItemHomeGameTestV2RecommendLabelCustomBinding
) : BaseRecyclerViewHolder<Any>(mBinding.root) {
    fun bind(data: RecommendLabel, linkText: String, pageLocation: PageLocation) {
        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,
                "新游开测",
                ""
            )
            SensorsBridge.trackColumnTestClick(
                location = "自定义页面",
                recommendType = linkText,
                text = "内容标签",
                bottomTab = pageLocation.bottomTab,
                multiTabName = pageLocation.severalTabPageName,
                multiTabId = pageLocation.severalTabPageId,
                position = pageLocation.tabPosition,
                tabContent = pageLocation.tabContent,
                customPageName = pageLocation.pageName,
                customPageId = pageLocation.pageId,
                buttonType = data.text,
                linkType = data.link.type,
                linkId = data.link.link,
                linkText = data.link.text
            )
        }
    }
}