package com.gh.gamecenter.search.viewmodel

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.gh.gamecenter.SearchActivity
import com.gh.gamecenter.common.base.GlobalActivityManager
import com.gh.gamecenter.common.utils.SensorsBridge

class SearchTabViewModel : ViewModel() {

    private val _searchKeyAndType = MutableLiveData<Pair<String, String>>()
    val searchKeyAndType: LiveData<Pair<String, String>> = _searchKeyAndType
    fun updateSearchKeyAndType(key: String, type: String) {
        _searchKeyAndType.value = key to type
    }

    fun trackGameSearchPageTabClick(location: String, text: String?, position: Int) {
        SensorsBridge.trackGameSearchPageTabClick(
            GlobalActivityManager.getCurrentPageEntity().pageId,
            GlobalActivityManager.getCurrentPageEntity().pageName,
            location,
            searchKeyAndType.value?.first ?: "",
            searchKeyAndType.value?.let {
                SearchActivity.toTrackSearchType(it.second) } ?: "",
            text ?: "",
            position
        )
    }
}