package com.gh.gamecenter.gamecollection.detail

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.View
import com.gh.gamecenter.R
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.core.utils.DisplayUtils

/**
 * 游戏单详情
 */
class GameCollectionDetailActivity : ToolBarActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        hideToolbar(true)
        DisplayUtils.setStatusBarColor(this, com.gh.gamecenter.common.R.color.transparent, false)
    }

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

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

    override fun isAutoResetViewBackgroundEnabled(): Boolean = true

    override fun updateStaticViewBackground(view: View?) {
        updateStaticView(view, listOf(R.id.bottomStarIv, R.id.bottomLikeIv))
    }

    companion object {
        @JvmStatic
        fun getIntent(
            context: Context,
            gameCollectionId: String,
            isFromSquare: Boolean = false,
            entrance: String = ""
        ): Intent {
            return getIntent(context, gameCollectionId, "", isFromSquare, false, entrance = entrance)
        }

        @JvmStatic
        fun getSpecifiedCommentIntent(
            context: Context,
            gameCollectionId: String,
            topCommentId: String,
            entrance: String
        ): Intent {
            return getIntent(
                context, gameCollectionId, topCommentId,
                isFromSquare = false,
                isScrollToCommentArea = true,
                entrance = entrance
            )
        }

        @JvmStatic
        fun getIntent(
            context: Context,
            gameCollectionId: String,
            topCommentId: String = "",
            isFromSquare: Boolean = false,
            isScrollToCommentArea: Boolean = false,
            exposureSourceList: ArrayList<ExposureSource>? = null,
            entrance: String = ""
        ): Intent {
            val bundle = Bundle()
            bundle.putString(EntranceConsts.KEY_GAME_COLLECTION_ID, gameCollectionId)
            bundle.putString(EntranceConsts.KEY_TOP_COMMENT_ID, topCommentId)
            bundle.putBoolean(EntranceConsts.KEY_IS_FROM_SQUARE, isFromSquare)
            bundle.putBoolean(EntranceConsts.KEY_SCROLL_TO_COMMENT_AREA, isScrollToCommentArea)
            bundle.putString(EntranceConsts.KEY_ENTRANCE, entrance)
            if (exposureSourceList != null) {
                bundle.putParcelableArrayList(EntranceConsts.KEY_EXPOSURE_SOURCE_LIST, exposureSourceList)
            }
            return getTargetIntent(
                context,
                GameCollectionDetailActivity::class.java,
                GameCollectionDetailFragment::class.java,
                bundle
            )
        }
    }
}