package com.zj365.health.act.exception

import android.content.Context
import android.view.View
import android.widget.TextView
import com.alibaba.android.arouter.facade.annotation.Route
import com.github.mikephil.charting.components.IMarker
import com.github.mikephil.charting.components.MarkerView
import com.github.mikephil.charting.components.YAxis
import com.github.mikephil.charting.data.BarEntry
import com.github.mikephil.charting.data.Entry
import com.github.mikephil.charting.highlight.Highlight
import com.tamsiree.rxkit.RxTimeTool
import com.xty.common.arouter.ARouterUrl
import com.zj365.health.R
import com.zj365.health.vm.ExceptionVm
import com.xty.network.model.ExceptionBean
import java.text.SimpleDateFormat

/**
 *  心率异常数据
 */
@Route(path = ARouterUrl.XINLV_EXCEPTION_DATA_ACT)
class XinlvExceptionDataAct : BaseExceptionDataAct<ExceptionVm>() {
    override fun getUnit(): String {
        return "次/分"
    }

    override fun getHint(): String {
        return "正常心率：50-100次/分"
    }

    override fun setLabelCount(leftAxis: YAxis) {
        leftAxis.setLabelCountAndMaxMinValue(6,false,0f,160f)
    }

    override fun getMarkView(): IMarker? {
        return CustomMarkerViewXXinlv(
            this,
            R.layout.custom_marker_view_xinlv,result)
    }
    class CustomMarkerViewXXinlv(context: Context?, layoutResource: Int, var result:MutableList<ExceptionBean>) :
        MarkerView(context, layoutResource) {
        private val mData: TextView
        private val mTime: TextView
        override fun refreshContent(e: Entry, highlight: Highlight) {
            // 在 refreshContent 方法中设置需要显示的内容。
            val barEntry = e as BarEntry
            val x = barEntry.x
            val get = result.get(x.toInt())
            var data = get.data+"次/分"
            mData.setText(data)
            mTime.setText(    RxTimeTool.milliseconds2String(
                get.time.toLong() * 1000,
                SimpleDateFormat("HH :mm")
            ))
            setOffset((-getWidth() / 2).toFloat(), (-getHeight()).toFloat() - 10f);
        }

        init {
            // 在构造函数中获取 MarkerView 中的 TextView。
            mData = findViewById<View>(R.id.tvDataXinlv) as TextView
            mTime = findViewById<View>(R.id.tvTime) as TextView
        }
    }

    override fun getRangeMaxmum(): Float {
        return 100f
    }

    override fun getRangeMinmum(): Float {
        return 50f
    }
}