package com.gh.common.provider

import android.content.Context
import androidx.fragment.app.Fragment
import androidx.lifecycle.LiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import com.therouter.router.Route
import com.gh.gamecenter.common.constant.RouteConsts
import com.gh.gamecenter.core.provider.ISearchTabUtilsProvider
import com.gh.gamecenter.search.viewmodel.SearchTabViewModel

@com.therouter.inject.ServiceProvider
class SearchTabUtilsProviderImpl : ISearchTabUtilsProvider {

    override fun obtainParentViewModel(fragment: Fragment): ViewModel {
        val store = (fragment.parentFragment ?: fragment).viewModelStore
        val factory = fragment.defaultViewModelProviderFactory
        return ViewModelProvider(
            store,
            factory
        ).get(SearchTabViewModel::class.java)
    }

    override fun getKeyAndTypeLiveData(viewModel: ViewModel?): LiveData<Pair<String, String>>? =
        if (viewModel is SearchTabViewModel) {
            viewModel.searchKeyAndType
        } else {
            null
        }

}
