package com.gh.gamecenter.adapter.viewholder

import android.view.View
import android.view.ViewGroup
import com.gh.gamecenter.common.base.BaseRecyclerViewHolder
import com.gh.gamecenter.common.utils.dip2px
import com.gh.gamecenter.common.utils.goneIf
import com.gh.gamecenter.common.utils.toColor
import com.gh.gamecenter.databinding.GameHeadItemBinding
import com.gh.gamecenter.entity.SubjectEntity

/**
 * 专题头部
 */
class GameHeadViewHolder(var binding: GameHeadItemBinding) :
    BaseRecyclerViewHolder<Any>(binding.root) {

    fun bindHead(subject: SubjectEntity) {
        val headContainerLp = binding.headContainer.layoutParams
        if (subject.showName) {
            headContainerLp.height = ViewGroup.LayoutParams.WRAP_CONTENT
            binding.headContainer.layoutParams = headContainerLp
            binding.headContainer.visibility = View.VISIBLE
        } else {
            headContainerLp.height = 8F.dip2px()
            binding.headContainer.layoutParams = headContainerLp
            binding.headContainer.visibility = View.INVISIBLE
            return
        }

        binding.headTitle.text = subject.getFilterName()
        binding.headPb.visibility = View.GONE
        binding.arrowIv.visibility = View.GONE
        val text = if ("change" == subject.home) {
            "换一批"
        } else {
            when (subject.home) {
                "more" -> "更多"
                "hide" -> ""
                "game_list_square" -> "游戏单广场"
                else -> "全部"
            }
        }
        binding.headMore.text = text

        if (subject.indexRightTop != null && subject.indexRightTop != "none") {
            // 开测表用到的
            binding.headMore.visibility = View.VISIBLE
            if (subject.indexRightTop == "all") {
                binding.headMore.text = "全部"
            } else {
                binding.headMore.text = "更多"
            }
        } else if (text == "全部"
            && subject.data != null
            && subject.data!!.size >= subject.more ?: 0
            && subject.type != "column_collection"
            && subject.type != "gallery_slide"
            && subject.type != "game_list_collection"
            && subject.type != "top_game_comment"
        ) {
            binding.headMore.visibility = View.GONE
        } else if (subject.home == "hide") {
            binding.headMore.visibility = View.GONE
        } else {
            binding.headMore.visibility = View.VISIBLE
        }
        if (binding.headMore.visibility == View.VISIBLE && (binding.headMore.text == "更多" || binding.headMore.text == "全部" || binding.headMore.text == "游戏单广场")) {
            binding.arrowIv.visibility = View.VISIBLE
        }
        binding.headTitle.setTextColor(com.gh.gamecenter.common.R.color.text_primary.toColor(binding.root.context))
        binding.adLabelTv.goneIf(!subject.adIconActive)
    }
}
