package com.gh.gamecenter.personalhome

import android.os.Bundle
import android.view.View
import com.therouter.router.Autowired
import com.therouter.router.Route
import com.therouter.TheRouter
import com.gh.gamecenter.common.base.activity.ToolBarActivity
import com.gh.gamecenter.R
import com.gh.gamecenter.common.constant.EntranceConsts
import com.gh.gamecenter.common.constant.RouteConsts
import com.gh.gamecenter.core.utils.DisplayUtils

@Route(
    path = RouteConsts.activity.userHomeActivity,
    description = "个人主页"
)
class UserHomeActivity : ToolBarActivity() {

    @JvmField
    @Autowired(name = EntranceConsts.KEY_USER_ID, description = "用户 id （长 id 或短 id 均可）", required = true)
    var userId: String? = null

    @JvmField
    @Autowired(name = EntranceConsts.KEY_TAB_INDEX, description = "默认选中 tab 的序号，可选值 0 游戏，1 发布")
    var selectedTabIndex: Int = 0

    @JvmField
    @Autowired(name = EntranceConsts.KEY_COMMUNITY_TYPE, description = "默认选中的社区内容 tab 类型，可选值 all: 全部, video: 视频, community_article: 帖子, answer: 回答, question: 问题")
    var selectedCommunityType: String = ""

    @JvmField
    @Autowired(name = EntranceConsts.KEY_GAME_TYPE, description = "默认选中的游戏 tab 类型，可选值 game_collection: 游戏单, played_game: 玩过, comment: 评价")
    var selectedGameType: String = ""

    @JvmField
    @Autowired(name = EntranceConsts.KEY_PATH, description = "页面路径 （历史代码用到的，传不传都行）")
    var path: String = ""

    override fun onCreate(savedInstanceState: Bundle?) {
        // 注入 arouter 参数
        TheRouter.inject(this)

        // 桥接 arouter 和原有入参
        generateDataFromRoute()

        super.onCreate(savedInstanceState)
        hideToolbar(true)
        DisplayUtils.setStatusBarColor(this, com.gh.gamecenter.common.R.color.transparent, false)
    }

    override fun getBusinessId(): Pair<String, String> {
        return Pair(userId ?: "", "")
    }

    override fun isAutoResetViewBackgroundEnabled(): Boolean = true

    override fun updateStaticViewBackground(view: View?) {
        updateStaticView(
            view,
            listOf(R.id.allType, R.id.videoType, R.id.articleType, R.id.questionType, R.id.answerType, R.id.tab_title)
        )
    }

    private fun generateDataFromRoute() {
        val bundle = intent.extras

        intent?.putExtra(NORMAL_FRAGMENT_NAME, UserHomeFragment::class.java.canonicalName)
        intent?.putExtra(NORMAL_FRAGMENT_BUNDLE, bundle)
    }
}