package com.duben.microtribe.ui.adapter

import androidx.fragment.app.Fragment
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.duben.microtribe.mvp.model.HotStyleTypesBean
import com.duben.microtribe.ui.fragment.MovieFragment

class HomeVideoPageAdapter(
    private val data: List<HotStyleTypesBean>,
    fragment: Fragment
) :
    FragmentStateAdapter(fragment) {

    private val fragments = mutableMapOf<Int, Fragment>()

    override fun getItemId(position: Int): Long {
        return data[position].torder.toLong()
    }

    override fun getItemCount() = data.size

    override fun createFragment(position: Int): Fragment {
        val newFragment = MovieFragment.newInstance(data[position].typeId,position)
        fragments[position] = newFragment
        return newFragment
    }

    override fun containsItem(itemId: Long): Boolean {
        data.forEach {
            if (it.torder.toLong() == itemId) {
                return true
            }
        }
        return false
    }

    fun getFragments(): MutableMap<Int, Fragment> {
        return fragments
    }

}