package com.gh.gamecenter.qa.article.detail

import android.os.Bundle
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentPagerAdapter
import com.gh.gamecenter.common.constant.EntranceConsts

/**
 * 资讯详情-评论&相关-页面适配器
 */
class ArticleDetailCommentPagerAdapter(
    fragmentManager: FragmentManager,
    private val entrance: String,
    showRelatedContent: Boolean
) : FragmentPagerAdapter(fragmentManager) {

    val tabList = if (showRelatedContent) {
        listOf("评论 0", "相关")
    } else {
        listOf("评论 0")
    }

    companion object {
        const val POSITION_COMMENT_LIST = 0
        const val POSITION_RELATED_CONTENTS = 1
    }

    override fun getCount(): Int = tabList.size

    override fun getItem(position: Int): Fragment = when(position) {
        POSITION_COMMENT_LIST -> ArticleDetailCommentListFragment().apply {
            arguments = Bundle().apply {
                putString(EntranceConsts.KEY_ENTRANCE, entrance)
            }
        }
        POSITION_RELATED_CONTENTS -> ArticleDetailRelatedContentListFragment().apply {
            arguments = Bundle().apply {
                putString(EntranceConsts.KEY_ENTRANCE, entrance)
            }
        }

        else -> throw IndexOutOfBoundsException("illegal fragment type!")
    }
}