package com.zj365.mime.fragment

import android.view.View
import com.xty.base.fragment.BaseVmFrag
import com.xty.common.util.CommonToastUtils
import com.zj365.mime.databinding.FragDetailResultBinding
import com.zj365.mime.vm.SportDetailVm
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode

class SportDetailResultFrag : BaseVmFrag<SportDetailVm>() {

    val binding by lazy { FragDetailResultBinding.inflate(layoutInflater) }
    override fun setViewModel() = SportDetailVm()


    override fun initView() {
        super.initView()
        mViewModel.userId = requireArguments().getString("userId").toString()
        mViewModel.id = requireArguments().getString("id").toString()

        mViewModel.findSportsPlanDetail()
    }


    override fun observer() {
        mViewModel.accessLive.observe(this) {
            CommonToastUtils.showSucceedToast("提交成功")
            EventBus.getDefault().post("refresh")
            activity?.finish()
        }
        mViewModel.detailLive.observe(this) {
            it.data.let {
                binding.mV1.apply {
                    setValues(it.sportsWay, false)

                }
                binding.mV2.setValues(it.sportsStrength, false)
                binding.mV3.setValues(it.sportsAerobic, false)
                binding.mV4.setValues(it.duration, false)
                binding.mV5.setValues(it.distance, false)
                binding.mV6.setValues(it.speedResistance, false)
                binding.mV7.setValues(it.calorie, false)
                binding.mV8.apply {
                    setValues(it.finishTime, false)
                }
                binding.mTvContent.apply {
                    visibility = View.VISIBLE
                    text = it.evaluationResult

                }
            }

        }
    }

    override fun setLayout() = binding.root


    @Subscribe(threadMode = ThreadMode.MAIN)
    fun refreshList(str: String) {
        mViewModel.findSportsPlanDetail()
    }
}