package com.zj365.health.act

import com.alibaba.android.arouter.facade.annotation.Route
import com.xty.base.act.BaseVmAct
import com.xty.common.TimeSelect
import com.xty.common.arouter.ARouterUrl
import com.xty.common.arouter.RouteManager
import com.xty.common.util.CommonToastUtils
import com.zj365.health.databinding.ActBloodStudyBinding
import com.zj365.health.vm.BloodCalibrationVm

/**
 * 血压校准
 */
@Route(path = ARouterUrl.BLOOD_STUDY)
class BloodStudyAct : BaseVmAct<BloodCalibrationVm>() {
    val timSelect by lazy {
        TimeSelect(this) {
        }.apply {
            showHour = true
            showMin = true
            showSec = false
        }
    }

    val binding by lazy { ActBloodStudyBinding.inflate(layoutInflater) }
    override fun liveObserver() {
        mViewModel.recordStudyLive.observe(this) {
            CommonToastUtils.showToast(it.data)
            binding.edHighXy.text.clear()
            binding.edLowXy.text.clear()
        }
    }

    override fun setLayout() = binding.root
    override fun initData() {
        super.initData()
    }

    override fun initView() {
        super.initView()
        statusBar(binding.title.mView)
        binding.title.mIvBack.setOnClickListener { finish() }
        binding.title.mTvTitle.text = "血压学习"
        binding.mTip.setOnClickListener {
//            var webUrl = "https://mp.weixin.qq.com/s/gQdOW45OfSU0Y-J-zhHq1A"
//            bundle.clear()
//            bundle.putString("title", "血压学习须知")
//            bundle.putString("url", webUrl)
            RouteManager.goAct(ARouterUrl.BLOOD_STUDY_NEED_KNOW)
        }
        binding.tvStudyRecord.setOnClickListener {
            RouteManager.goAct(ARouterUrl.XUEYA_XUEXIJILU)
        }
        binding.tvBindDeviceImdiatly.setOnClickListener {
            val edHighXy = binding.edHighXy.text.toString().trim()
            if (edHighXy.isNullOrEmpty()){
                CommonToastUtils.showToast("请输入您测量的高压数据")
                return@setOnClickListener
            }
            val edLowXy = binding.edLowXy.text.toString().trim()
            if (edLowXy.isNullOrEmpty()){
                CommonToastUtils.showToast("请输入您测量的低压数据")
                return@setOnClickListener
            }
            var gbp = edHighXy.toInt()
            var dbp = edLowXy.toInt()
            // gbp 高压
            // dbp 低压
            if (gbp <= 70||dbp>=260||dbp<=40||dbp>=150||dbp>gbp){
                CommonToastUtils.showToast("您输入的信息有误，请重新输入有效值")
                return@setOnClickListener
            }
            mViewModel.createStudyRecord(edHighXy.toInt(),edLowXy.toInt())
        }
    }
}