package com.gh.gamecenter

import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.fragment.app.Fragment
import com.gh.gamecenter.common.base.activity.BaseActivity_TabLayout
import com.gh.gamecenter.common.utils.updateStatusBarColor
import com.gh.gamecenter.help.HelpContainerFragment
import com.gh.gamecenter.suggest.SuggestSelectFragment
import com.lightgame.utils.Util_System_Keyboard

class HelpAndFeedbackActivity : BaseActivity_TabLayout() {

    override fun getLayoutId(): Int {
        return R.layout.activity_help_and_feedback
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (requestCode == SuggestSelectFragment.SUGGEST_TYPE_REQUEST
            && resultCode == SuggestSelectFragment.SUGGEST_TYPE_REQUEST
        ) {
            finish()
        }
    }

    override fun initFragmentList(fragments: MutableList<Fragment>) {
        fragments.add(HelpContainerFragment())
        fragments.add(SuggestSelectFragment())
    }

    override fun initTabTitleList(tabTitleList: MutableList<String>) {
        tabTitleList.add("使用帮助")
        tabTitleList.add("意见反馈")
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setNavigationTitle("帮助与反馈")
        val defaultPosition = intent.getIntExtra(PAGE_INDEX, HELP_ITEM)
        setCurrentItem(defaultPosition)
        updateStatusBarColor(R.color.background_white, R.color.background_white)
    }

    override fun onPageSelected(position: Int) {
        super.onPageSelected(position)
        if (position == SUGGESTION_ITEM) {
            Util_System_Keyboard.hideSoftKeyboard(this)
        }
    }

    fun setCurrentItem(position: Int) {
        mViewPager.currentItem = position
    }

    override fun isAutoResetViewBackgroundEnabled() = true

    override fun onDarkModeChanged() {
        super.onDarkModeChanged()
        updateStatusBarColor(R.color.background_white, R.color.background_white)
    }

    companion object {

        const val HELP_ITEM = 0
        const val SUGGESTION_ITEM = 1

        @JvmStatic
        fun getIntent(context: Context, position: Int = HELP_ITEM): Intent {
            val intent = Intent(context, HelpAndFeedbackActivity::class.java)
            intent.putExtra(PAGE_INDEX, position)
            return intent
        }
    }
}