package com.gh.gamecenter.feedback.view.suggest

import android.os.Bundle
import android.view.View
import androidx.recyclerview.widget.RecyclerView
import com.therouter.TheRouter
import com.gh.gamecenter.common.baselist.ListFragment
import com.gh.gamecenter.common.constant.RouteConsts
import com.gh.gamecenter.common.utils.ShareUtils
import com.gh.gamecenter.common.utils.updateStatusBarColor
import com.gh.gamecenter.common.utils.viewModelProvider
import com.gh.gamecenter.core.provider.IConfigProvider
import com.gh.gamecenter.core.provider.IDirectProvider
import com.gh.gamecenter.feedback.databinding.FragmentSuggestionBinding
import com.gh.gamecenter.feedback.entity.SuggestionItem

class SuggestionCategoryFragment : ListFragment<SuggestionItem, SuggestionCategoryViewModel>() {
    private lateinit var mBinding: FragmentSuggestionBinding
    private lateinit var mViewModel: SuggestionCategoryViewModel
    private var mAdapter: SuggestionCategoryAdapter? = null

    override fun getLayoutId(): Int = 0

    override fun getInflatedLayout(): View =
        FragmentSuggestionBinding.inflate(layoutInflater, null, false).apply { mBinding = this }.root

    override fun provideListViewModel(): SuggestionCategoryViewModel {
        mViewModel = viewModelProvider()
        return mViewModel
    }

    override fun provideListAdapter(): SuggestionCategoryAdapter {
        if (mAdapter == null) {
            mAdapter = SuggestionCategoryAdapter(requireContext(), arguments)
        }
        return mAdapter as SuggestionCategoryAdapter
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        requireActivity().updateStatusBarColor(com.gh.gamecenter.common.R.color.ui_surface, com.gh.gamecenter.common.R.color.ui_surface)
        setNavigationTitle("意见反馈")

        val configProvider = TheRouter.get(IConfigProvider::class.java)
        val directProvider = TheRouter.get(IDirectProvider::class.java)
        if (!configProvider?.getQQun().isNullOrEmpty()) {
            mBinding.suggestQqun.text = configProvider?.getQQun()
        }
        mBinding.suggestQunContainer.setOnClickListener {
            if (ShareUtils.isQQClientAvailable(requireContext())) {
                var groupNumber = "vd754P2_uNUJqDcgX4V-pyXEGZZVH0DE"
                if (!configProvider?.getQQunKey().isNullOrEmpty()) {
                    groupNumber = configProvider?.getQQunKey()!!
                }
                directProvider?.directToQqGroup(requireContext(), groupNumber) // Q群：367541038 KEY
            } else {
                toast("请先安装QQ")
            }
        }
        mListRefresh?.isEnabled = false
    }

    override fun getItemDecoration(): RecyclerView.ItemDecoration? = null
}