package com.gh.gamecenter.search

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.feature.entity.SettingsEntity

class SearchDefaultRankListAdapter(
    private val mContext: Context,
    private val mViewModel: SearchDefaultViewModel,
    private val mRankList: List<SettingsEntity.Search.RankList>,
    private val mPageWidth: Float,
    private val mIsGameSearch: Boolean,
    private val mSourceEntrance: String
) : 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)
        }

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