package com.gamedog.vididin.main.fragments.home


import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.viewpager2.adapter.FragmentStateAdapter


class HomeVpLoopAdapter<T>(
    private val activity: FragmentActivity,
    private val dataList: List<T>,
    private val fragmentCreatorFun: (List<T>, Int) -> Fragment
) : FragmentStateAdapter(activity) {

    companion object {
        private const val LOOP_FRAGMENT_COUNT = 3
    }

    private val mRealPageCount = LOOP_FRAGMENT_COUNT

    override fun getItemCount(): Int = Int.MAX_VALUE

    override fun createFragment(position: Int): Fragment {
        val fragmentPosition = position % mRealPageCount
        return fragmentCreatorFun(dataList, fragmentPosition)
    }

}
