package com.gh.gamecenter.subject

import android.content.Context
import android.content.Intent
import android.os.Bundle
import com.gh.base.DownloadToolbarActivity
import com.gh.gamecenter.R
import com.gh.gamecenter.common.constant.EntranceConsts
import com.gh.gamecenter.common.utils.updateStatusBarColor
import com.gh.gamecenter.core.utils.MtaHelper
import com.gh.gamecenter.entity.SubjectData

class SubjectActivity : DownloadToolbarActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        updateStatusBarColor(R.color.background_white, R.color.background_white)
    }

    override fun showDownloadMenu() = true

    override fun getActivityNameInChinese() = "专题详情"

    override fun getBusinessId(): Pair<String, String> {
        val subjectData: SubjectData =
            intent.getBundleExtra(NORMAL_FRAGMENT_BUNDLE)?.getParcelable(EntranceConsts.KEY_SUBJECT_DATA)
                ?: SubjectData("", "", false)
        return Pair(subjectData.subjectId ?: "", "")
    }

    override fun provideNormalIntent(): Intent {
        return getTargetIntent(this, SubjectActivity::class.java, SubjectFragment::class.java)
    }

    override fun isAutoResetViewBackgroundEnabled() = true

    override fun onDarkModeChanged() {
        super.onDarkModeChanged()

        updateStatusBarColor(R.color.background_white, R.color.background_white)
    }

    companion object {
        /**
         * 启动专题页面
         */
        @JvmStatic
        fun startSubjectActivity(context: Context, id: String?, name: String?, isOrder: Boolean, entrance: String?) {
            MtaHelper.onEvent("详情页面", "专题详情", name)

            val bundle = Bundle()
            bundle.putString(EntranceConsts.KEY_ENTRANCE, entrance)
            val subjectData = SubjectData(subjectId = id, subjectName = name, isOrder = isOrder)
            bundle.putParcelable(EntranceConsts.KEY_SUBJECT_DATA, subjectData)
            bundle.putString(EntranceConsts.KEY_ENTRANCE, entrance)
            context.startActivity(
                getTargetIntent(
                    context,
                    SubjectActivity::class.java,
                    SubjectFragment::class.java,
                    bundle
                )
            )
        }
    }
}