package com.gh.gamecenter.home.gamecollection.slide

import androidx.constraintlayout.widget.ConstraintLayout
import androidx.recyclerview.widget.RecyclerView
import com.gh.gamecenter.common.base.BaseRecyclerViewHolder
import com.gh.gamecenter.common.utils.dip2px
import com.gh.gamecenter.common.view.FixLinearLayoutManager
import com.gh.gamecenter.databinding.HomeGameCollectionSlideItemBinding
import com.gh.gamecenter.entity.GameListCollection
import com.gh.gamecenter.home.LegacyHomeFragmentAdapterAssistant

/**
 * 首页内容列表/版块内容列表-游戏单合集-横排滑动-大卡片/小卡片
 */
class HomeGameCollectionSlideViewHolder(val binding: HomeGameCollectionSlideItemBinding) :
    BaseRecyclerViewHolder<Any>(binding.root) {

    private var mIsBigSlide = false
    private var mAdapter: HomeGameCollectionSlideAdapter? = null

    fun bindGameCollectionSlide(
        gameListCollection: GameListCollection,
        entrance: String,
        blockId: String = "",
        blockName: String = ""
    ) {
        val isBigSlide = gameListCollection.style == LegacyHomeFragmentAdapterAssistant.GAME_COLLECTION_BIG_SLIDE_STYLE
        if (binding.recyclerView.adapter is HomeGameCollectionSlideAdapter && mIsBigSlide == isBigSlide) {
            mAdapter?.checkResetData(gameListCollection, mIsBigSlide)
            return
        }

        mIsBigSlide = isBigSlide
        mAdapter = HomeGameCollectionSlideAdapter(
            binding.root.context,
            mIsBigSlide,
            entrance,
            gameListCollection,
            blockId,
            blockName
        )
        binding.recyclerView.run {
            layoutParams = (layoutParams as ConstraintLayout.LayoutParams).also {
                it.height = if (mIsBigSlide) 333F.dip2px() else 198F.dip2px()
            }
            layoutManager = FixLinearLayoutManager(context, RecyclerView.HORIZONTAL, false)
            adapter = mAdapter
        }
    }
}