package cn.muchinfo.rma.view.base.home.reportquery

import android.annotation.SuppressLint
import android.view.Gravity
import androidx.appcompat.app.AppCompatActivity
import cn.muchinfo.rma.R
import cn.muchinfo.rma.global.data.ExposureReportData
import cn.muchinfo.rma.global.toPercentage
import cn.muchinfo.rma.lifecycle.bindOptional
import cn.muchinfo.rma.view.autoWidget.autoSize
import cn.muchinfo.rma.view.autoWidget.textColorInt
import cn.muchinfo.rma.view.autoWidget.textSizeAuto
import mtp.polymer.com.autowidget.adapter.BaseViewHolder
import org.jetbrains.anko.*

/**
 * 报表查询敞口
 * @property activity AppCompatActivity
 * @property viewModel ReportQueryViewModel
 * @property itemSize IntArray
 * @constructor
 */
class ExposureReportViewholder(private val activity: AppCompatActivity,private val viewModel: ReportQueryViewModel) : BaseViewHolder<ExposureReportData>(activity){
    override val itemSize: IntArray = intArrayOf(matchParent, wrapContent)

    @SuppressLint("SetTextI18n")
    override fun _FrameLayout.createContentView() {
        linearLayout {
            verticalLayout {
                gravity = Gravity.START
                textView {
                    data.bindOptional(context){
                        text = it?.middlegoodsname
                    }
                    textSizeAuto = 24
                    textColorInt = R.color.hint_text_color
                }.lparams(wrapContent, wrapContent){
                    marginStart = autoSize(36)
                    topMargin = autoSize(15)
                }

                textView {
                    data.bindOptional(context){
                        text = it?.middlegoodscode
                    }
                    textSizeAuto = 24
                    textColorInt = R.color.hint_text_color
                }.lparams(wrapContent, wrapContent){
                    marginStart = autoSize(36)
                }
            }.lparams(autoSize(225), autoSize(100))

            verticalLayout {
                gravity = Gravity.CENTER
                textView {
                    data.bindOptional(context){
                        text = it?.totalspotqty + it?.enumdicname
                    }
                    textSizeAuto = 24
                    textColorInt = R.color.hint_text_color
                }.lparams(wrapContent, wrapContent)

                textView {
                    data.bindOptional(context){
                        text = it?.middlegoodshedgeratio?.toPercentage()
                    }
                    textSizeAuto = 24
                    textColorInt = R.color.hint_text_color
                }.lparams(wrapContent, wrapContent)
            }.lparams(autoSize(225), autoSize(100))

            verticalLayout {
                gravity = Gravity.CENTER
                textView {
                    data.bindOptional(context){
                        text = it?.totalneedhedgeqty + it?.enumdicname
                    }
                    textSizeAuto = 24
                    textColorInt = R.color.hint_text_color
                }.lparams(wrapContent, wrapContent)

                textView {
                    data.bindOptional(context){
                        text = it?.totalfutureqty + it?.enumdicname
                    }
                    textSizeAuto = 24
                    textColorInt = R.color.hint_text_color
                }.lparams(wrapContent, wrapContent)
            }.lparams(autoSize(225), autoSize(100))

            verticalLayout {
                gravity = Gravity.END
                textView {
                    data.bindOptional(context){
                        text = it?.needhedgeexposoure + it?.enumdicname
                    }
                    textSizeAuto = 24
                    textColorInt = R.color.hint_text_color
                }.lparams(wrapContent, wrapContent){
                    marginEnd = autoSize(36)
                    topMargin = autoSize(15)
                }

                textView {
                     data.bindOptional(context){
                        text = it?.needhedgeratio?.toPercentage()
                    }
                    textSizeAuto = 24
                    textColorInt = R.color.hint_text_color
                }.lparams(wrapContent, wrapContent){
                    marginEnd = autoSize(36)
                }
            }.lparams(autoSize(225), autoSize(100))
        }.lparams(matchParent, autoSize(100))
    }

}