package com.gh.gamecenter.minigame

import android.content.Context
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.gh.gamecenter.R
import com.gh.gamecenter.adapter.RecyclingPagerAdapter
import com.gh.gamecenter.common.utils.dip2px
import com.gh.gamecenter.feature.entity.SettingsEntity

/**
 * 微信小游戏-搜索榜单
 */
class MiniGameSearchDefaultRankListAdapter(
    private val mContext: Context,
    private val mRankList: List<SettingsEntity.Search.RankList>,
    private val mPageWidth: Float
) : RecyclingPagerAdapter() {

    override fun getCount() = mRankList.size

    override fun getPageWidth(position: Int) = mPageWidth

    override fun getPageTitle(position: Int) = mRankList[position].title

    override fun getView(position: Int, convertView: View?, container: ViewGroup?): View {
        var view: View? = convertView
        if (convertView == null) {
            view = View.inflate(mContext, R.layout.search_default_rank_list_item, null).apply {
                findViewById<RecyclerView>(R.id.rankContainer).apply {
                    setPadding(16F.dip2px(), 16F.dip2px(), 16F.dip2px(), 16F.dip2px())
                }
            }
            container?.layoutParams?.height = 432F.dip2px()
        }

        view!!.findViewById<RecyclerView>(R.id.rankContainer).run {
            layoutManager = LinearLayoutManager(mContext)
            adapter = MiniGameSearchDefaultRankAdapter(mContext, mRankList[position])

        }
        return view
    }
}