package com.dlc.exam.ui.mock

import android.annotation.SuppressLint
import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.lifecycle.ViewModelProvider
import com.dlc.exam.common.CommonUtils
import com.dlc.exam.databinding.FragmentMockTestCompletedBinding
import com.dlc.exam.ui.score.PaperQuViewModel
import com.rc.core.ui.fragment.RcBaseFragment

/**
 * info
 *
 * @author ReiChin_
 */
class MockTestCompletedFragment : RcBaseFragment<FragmentMockTestCompletedBinding>() {

    companion object {
        const val FRAGMENT_TAG = "MockTestCompletedFragment"
        fun newInstance() = MockTestCompletedFragment()
    }

    private val viewModel by lazy {
        ViewModelProvider(requireActivity(), ViewModelProvider.NewInstanceFactory()).get(
            PaperQuViewModel::class.java
        )
    }

    override fun createViewBinding(
        inflater: LayoutInflater,
        container: ViewGroup?
    ) = FragmentMockTestCompletedBinding.inflate(inflater, container, false)

    @SuppressLint("SetTextI18n")
    override fun initViews(savedInstanceState: Bundle?) {
        viewModel.handPractiseData.observe(viewLifecycleOwner) { data ->
            viewBinding.accuracy.text = data.accuracy
            viewBinding.points.text = CommonUtils.formatEmpty(data.points)
            viewBinding.unAnswered.text = "未答题数：${CommonUtils.formatEmpty(data.unAnswered)}"
            viewBinding.answered.text = "已答题数：${CommonUtils.formatEmpty(data.answered)}"
            viewBinding.errors.text = "错题数：${CommonUtils.formatEmpty(data.errors)}"
        }

        viewBinding.reMockTest.setOnClickListener {
            // 重新练习
            val intent = Intent(requireContext(), SelectedMockTypeActivity::class.java)
            startActivity(intent)
            requireActivity().finish()
        }
    }

}