package com.gh.gamecenter.qa.questions.newdetail

import android.content.Context
import android.content.Intent
import android.os.Bundle
import com.gh.gamecenter.common.base.activity.ToolBarActivity
import com.gh.gamecenter.R
import com.gh.gamecenter.common.constant.EntranceConsts
import com.gh.gamecenter.common.utils.updateStatusBarColor
import com.gh.gamecenter.common.entity.CommunityEntity

class NewQuestionDetailActivity : ToolBarActivity() {

    override fun getLayoutId() = R.layout.activity_amway

    override fun getFragmentPlaceholderId() = R.id.placeholder

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

//        TODO 让状态栏透明
//        DisplayUtils.transparentStatusBar(this)
        updateStatusBarColor(R.color.background_white, R.color.background_white)
    }

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

    override fun getBusinessId(): Pair<String, String> {
        return Pair(
            targetFragment.arguments?.getString(EntranceConsts.KEY_QUESTIONS_ID) ?: "",
            targetFragment.arguments?.getParcelable<CommunityEntity>(EntranceConsts.KEY_COMMUNITY_DATA)?.id
                ?: ""
        )
    }

    override fun isAutoResetViewBackgroundEnabled(): Boolean = true

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

    companion object {
        @JvmStatic
        fun getIntent(
            context: Context,
            questionId: String,
            entrance: String,
            path: String
        ): Intent {
            val intent = Intent(context, NewQuestionDetailActivity::class.java)
            intent.putExtra(EntranceConsts.KEY_ENTRANCE, mergeEntranceAndPath(entrance, path))
            intent.putExtra(EntranceConsts.KEY_QUESTIONS_ID, questionId)
            intent.putExtra(EntranceConsts.KEY_PATH, path)
            return intent
        }

        /**
         * 自动滚动到评论区域
         */
        @JvmStatic
        fun getCommentIntent(
            context: Context,
            questionId: String,
            entrance: String,
            path: String
        ): Intent {
            val intent = Intent(context, NewQuestionDetailActivity::class.java)
            intent.putExtra(EntranceConsts.KEY_ENTRANCE, mergeEntranceAndPath(entrance, path))
            intent.putExtra(EntranceConsts.KEY_QUESTIONS_ID, questionId)
            intent.putExtra(EntranceConsts.KEY_SCROLL_TO_COMMENT_AREA, true)
            intent.putExtra(EntranceConsts.KEY_PATH, path)
            return intent
        }

        @JvmStatic
        fun getCommentIntent(
            context: Context,
            questionId: String,
            answerId: String,
            entrance: String,
            path: String
        ): Intent {
            val intent = Intent(context, NewQuestionDetailActivity::class.java)
            intent.putExtra(EntranceConsts.KEY_ENTRANCE, mergeEntranceAndPath(entrance, path))
            intent.putExtra(EntranceConsts.KEY_QUESTIONS_ID, questionId)
            intent.putExtra(EntranceConsts.KEY_ANSWER_ID, answerId)
            intent.putExtra(EntranceConsts.KEY_SCROLL_TO_COMMENT_AREA, true)
            intent.putExtra(EntranceConsts.KEY_PATH, path)
            return intent
        }

        @JvmStatic
        fun getRecommendIntent(
            context: Context,
            questionId: String,
            answerId: String,
            recommendId: String,
            entrance: String,
            path: String,
            scrollToComment: Boolean = false
        ): Intent {
            val intent = Intent(context, NewQuestionDetailActivity::class.java)
            intent.putExtra(EntranceConsts.KEY_ENTRANCE, mergeEntranceAndPath(entrance, path))
            intent.putExtra(EntranceConsts.KEY_QUESTIONS_ID, questionId)
            intent.putExtra(EntranceConsts.KEY_ANSWER_ID, answerId)
            intent.putExtra(EntranceConsts.KEY_RECOMMEND_ID, recommendId)
            intent.putExtra(EntranceConsts.KEY_SCROLL_TO_COMMENT_AREA, scrollToComment)
            intent.putExtra(EntranceConsts.KEY_PATH, path)
            return intent
        }

        @JvmStatic
        fun getSpecifiedCommentIntent(
            context: Context,
            questionId: String,
            topCommentId: String,
            entrance: String,
            path: String
        ): Intent {
            val intent = Intent(context, NewQuestionDetailActivity::class.java)
            intent.putExtra(EntranceConsts.KEY_ENTRANCE, mergeEntranceAndPath(entrance, path))
            intent.putExtra(EntranceConsts.KEY_QUESTIONS_ID, questionId)
            intent.putExtra(EntranceConsts.KEY_TOP_COMMENT_ID, topCommentId)
            intent.putExtra(EntranceConsts.KEY_SCROLL_TO_COMMENT_AREA, true)
            intent.putExtra(EntranceConsts.KEY_PATH, path)
            return intent
        }
    }
}