package com.gh.gamecenter.feedback.view.help

import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.fragment.app.Fragment
import com.alibaba.android.arouter.facade.annotation.Route
import com.gh.gamecenter.common.base.activity.BaseActivity_TabLayout
import com.gh.gamecenter.common.constant.CommonConsts
import com.gh.gamecenter.common.constant.RouteConsts
import com.gh.gamecenter.common.utils.updateStatusBarColor
import com.gh.gamecenter.feedback.view.suggest.SuggestSelectFragment
import com.gh.gamecenter.floatingwindow.R
import com.lightgame.utils.Util_System_Keyboard

@Route(path = RouteConsts.activity.helpAndFeedbackActivity)
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 == CommonConsts.SUGGEST_TYPE_REQUEST
            && resultCode == CommonConsts.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, CommonConsts.TAB_MAIN)
        setCurrentItem(defaultPosition)
        updateStatusBarColor(R.color.background_white, R.color.background_white)
    }

    override fun onPageSelected(position: Int) {
        super.onPageSelected(position)
        if (position == CommonConsts.TAB_SUB) {
            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 {

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