package com.gh.gamecenter.game.commoncollection.detail

import android.content.Context
import android.content.Intent
import android.os.Bundle
import com.gh.gamecenter.common.base.activity.ToolBarActivity
import com.gh.gamecenter.common.constant.EntranceConsts
import com.gh.gamecenter.common.exposure.ExposureSource
import com.gh.gamecenter.common.utils.updateStatusBarColor

/**
 * 通用内容合集详情
 */
class CommonCollectionDetailActivity : ToolBarActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        updateStatusBarColor(com.gh.gamecenter.common.R.color.ui_surface, com.gh.gamecenter.common.R.color.ui_surface)
    }

    override fun provideNormalIntent(): Intent {
        return getTargetIntent(
            this,
            CommonCollectionDetailActivity::class.java,
            CommonCollectionDetailFragment::class.java,
            intent.putExtra(EntranceConsts.KEY_LOCATION, "合集详情").extras
        )
    }

    override fun isAutoResetViewBackgroundEnabled(): Boolean = true

    override fun onDarkModeChanged() {
        super.onDarkModeChanged()
        updateStatusBarColor(com.gh.gamecenter.common.R.color.ui_surface, com.gh.gamecenter.common.R.color.ui_surface)
    }

    override fun getBusinessId(): Pair<String, String> {
        val fragment = targetFragment as? CommonCollectionDetailFragment?
        return if (fragment?.arguments != null) {
            Pair(
                fragment.requireArguments().getString(EntranceConsts.KEY_COLLECTION_ID) ?: "",
                fragment.requireArguments().getString(EntranceConsts.KEY_BLOCK_ID) ?: ""
            )
        } else {
            super.getBusinessId()
        }
    }

    companion object {

        fun getIntent(
            context: Context,
            collectionId: String,
            blockId: String = "",
            blockName: String = "",
            entrance: String = "",
            exposureSourceList: ArrayList<ExposureSource>? = null
        ): Intent {
            val bundle = Bundle()
            bundle.putString(EntranceConsts.KEY_ENTRANCE, entrance)
            bundle.putString(EntranceConsts.KEY_BLOCK_ID, blockId)
            bundle.putString(EntranceConsts.KEY_BLOCK_NAME, blockName)
            bundle.putString(EntranceConsts.KEY_COLLECTION_ID, collectionId)
            bundle.putString(EntranceConsts.KEY_LOCATION, "合集详情")
            bundle.putParcelableArrayList(EntranceConsts.KEY_EXPOSURE_SOURCE_LIST, exposureSourceList)
            return getTargetIntent(
                context,
                CommonCollectionDetailActivity::class.java,
                CommonCollectionDetailFragment::class.java,
                bundle
            )
        }
    }
}