package com.gh.gamecenter.minigame

import android.content.Context
import android.content.Intent
import android.os.Bundle
import com.gh.gamecenter.DisplayType
import com.gh.gamecenter.SearchActivity
import com.gh.gamecenter.common.constant.EntranceConsts
import com.gh.gamecenter.db.ISearchHistoryDao
import com.gh.gamecenter.search.SearchDefaultFragment
import com.gh.gamecenter.search.SearchGameResultFragment

/**
 * 小游戏-搜索页面
 */
class MiniGameSearchActivity : SearchActivity() {

    override fun provideDao(): ISearchHistoryDao = MiniGameSearchDao()

    override fun updateDisplayType(type: DisplayType) {
        val transaction = when(type) {
            DisplayType.DEFAULT -> showFragment(
                SearchDefaultFragment::class.java.name,
                { MiniGameSearchDefaultFragment() }
            ) {
                it.arguments = Bundle().also { bundle ->
                    bundle.putBoolean(SearchDefaultFragment.KEY_IS_GAME_SEARCH, true)
                }
            }

            else -> showFragment(
                SearchGameResultFragment::class.java.name,
                { MiniGameSearchResultFragment() }
            ) {
                it.setParams(mSearchKey ?: "", mSearchType.value)
            }
        }
        mDisplayType = type
        transaction.commitAllowingStateLoss()
    }

    companion object {

        @JvmStatic
        fun getIntent(
            context: Context,
            hint: String,
            sourceEntrance: String,
            bottomTab: String = "",
            multiTabId: String = "",
            multiTabName: String = "",
            customPageId: String = "",
            customPageName: String = "",
            searchBoxPattern: String = ""
        ): Intent {
            val intent = Intent(context, MiniGameSearchActivity::class.java)
            intent.putExtra(EntranceConsts.KEY_HINT, hint)
            intent.putExtra(EntranceConsts.KEY_SOURCE_ENTRANCE, sourceEntrance)
            intent.putExtra(EntranceConsts.KEY_BOTTOM_TAB_NAME, bottomTab)
            intent.putExtra(EntranceConsts.KEY_MULTI_TAB_NAV_ID, multiTabId)
            intent.putExtra(EntranceConsts.KEY_MULTI_TAB_NAV_NAME, multiTabName)
            intent.putExtra(EntranceConsts.KEY_CUSTOM_PAGE_ID, customPageId)
            intent.putExtra(EntranceConsts.KEY_CUSTOM_PAGE_NAME, customPageName)
            intent.putExtra(EntranceConsts.KEY_SEARCH_BOX_PATTERN, searchBoxPattern)
            return intent
        }
    }

}