package cn.muchinfo.rma.view.base.exposure

import android.view.Gravity
import android.view.MotionEvent
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import butterknife.OnTouch
import cn.muchinfo.rma.R
import cn.muchinfo.rma.global.data.ExposureHistoryData
import cn.muchinfo.rma.lifecycle.bindOptional
import cn.muchinfo.rma.view.autoWidget.*
import com.github.aachartmodel.aainfographics.aachartcreator.*
import com.github.aachartmodel.aainfographics.aaoptionsmodel.AAScrollablePlotArea
import mtp.polymer.com.autowidget.adapter.BaseViewHolder
import org.jetbrains.anko.*

class HistoryExposureViewholder(
    private val baseFragment: Fragment,
    private val viewModel: ExposureViewModel
) : BaseViewHolder<ExposureHistoryData>(baseFragment.activity!!) {
    override val itemSize: IntArray = intArrayOf(matchParent, wrapContent)

    override fun _FrameLayout.createContentView() {

        verticalLayout {
            linearLayout {
                gravity = Gravity.CENTER_VERTICAL
                view {
                    background = resources.getDrawable(R.color.rma_blue_color)
                }.lparams(autoSize(4), autoSize(45)) {
                    marginStart = autoSize(36)
                }

                textView {
                    text = "标准铜（吨）"
                    textSizeAuto = 34
                    textColorInt = R.color.rma_blue_color
                }.lparams(wrapContent, wrapContent)
            }.lparams(matchParent, autoSize(84))

            chartview {

                val aaChartModel = AAChartModel()
                    .chartType(AAChartType.Areaspline)
                    .title("")
                    .yAxisTitle("")
                    .legendEnabled(false)
                    .yAxisGridLineWidth(0f)
                    .animationType(AAChartAnimationType.EaseOutQuart)
                    .legendEnabled(true)
                    .gradientColorEnable(true)
                    .markerRadius(2f)
                    .markerSymbol(AAChartSymbolType.Circle)
                    .markerSymbolStyle(AAChartSymbolStyleType.InnerBlank)
                    .scrollablePlotArea(
                        AAScrollablePlotArea()
                            .minWidth(3000)
                            .scrollPositionX(1f))

                data.bindOptional(context){
                    val list = it?.data
                    val totalexposureelement = AASeriesElement()
                        .lineWidth(2f)
                        .name("总敞口")
                        .step(true)
                        .data(list?.map { it.totalexposure }!!.toTypedArray())
                    val needhedgeexposoureelement = AASeriesElement()
                        .name("应套保敞口")
                        .step(true)
                        .data(list.map { it.needhedgeexposoure }.toTypedArray())
                    aaChartModel.categories(list.map { it.reckondate }.toTypedArray())
                    aaChartModel.series(arrayOf(totalexposureelement,needhedgeexposoureelement))
                    aa_drawChartWithChartModel(aaChartModel)
                }
            }.lparams(matchParent, autoSize(416))

        }.lparams(matchParent, autoSize(500))
    }

}