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

import android.view.Gravity
import androidx.appcompat.app.AppCompatActivity
import cn.muchinfo.rma.R
import cn.muchinfo.rma.global.ViewEnumUtils
import cn.muchinfo.rma.global.data.NumberSpotDetailsData
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 ExposureViewModel
 * @property type String 1 现货 2 期货
 * @constructor
 */
class ExposurePositionDetailsViewholder(
    private val activity: AppCompatActivity,
    private val viewModel: ExposureViewModel,
    private val type : String
): BaseViewHolder<NumberSpotDetailsData>(activity) {
    override val itemSize: IntArray = intArrayOf(matchParent, autoSize(110))

    override fun _FrameLayout.createContentView() {
        linearLayout {
            verticalLayout {
                gravity = Gravity.CENTER
                textView {
                    data.bindOptional(context){
                        if (type == "1"){
                            text = it?.strtime
                        }else{
                            text = it?.tradetime
                        }
                    }
                    textColorInt = R.color.rma_black_33
                    textSizeAuto = 24
                }.lparams(wrapContent, wrapContent)
                textView {
                    data.bindOptional(context){
                        if (type == "1"){
                            text = it?.relatedno
                        }else{
                            text = it?.goodscode
                        }
                    }
                    textColorInt = R.color.rma_black_33
                    textSizeAuto = 24
                }.lparams(wrapContent, wrapContent)
            }.lparams(autoSize(225), autoSize(92))

            verticalLayout {
                gravity = Gravity.CENTER
                textView {
                    data.bindOptional(context){
                        if (type == "1"){
                            text = ViewEnumUtils.getSpotPositionType(contracttype = it?.contracttype ?: "",logtype = it?.logtype ?: "")
                        }else{
                            text = ViewEnumUtils.getBuyorsellType(it?.buyorsell ?: "0")
                        }
                    }
                    textColorInt = R.color.rma_black_33
                    textSizeAuto = 24
                }.lparams(wrapContent, wrapContent)
            }.lparams(autoSize(225), autoSize(92))

            verticalLayout {
                gravity = Gravity.CENTER
                textView {
                     data.bindOptional(context){
                        if (type == "1"){
                            text = it?.wrstandardname
                        }else{
                            text = ViewEnumUtils.getchannelbuildtype(it?.channelbuildtype ?: "")
                        }
                    }
                    textColorInt = R.color.rma_black_33
                    textSizeAuto = 24
                }.lparams(wrapContent, wrapContent)

            }.lparams(autoSize(225), autoSize(92))

            verticalLayout {
                gravity = Gravity.RIGHT
                textView {
                    data.bindOptional(context){
                        if (type == "1"){
                            text = it?.qty + it?.enumdicname
                        }else{
                            text = if (it?.buyorsell == "0"){""} else{"-"} + it?.tradeqty
                        }
                    }
                    textColorInt = R.color.rma_black_33
                    textSizeAuto = 24
                }.lparams(wrapContent, wrapContent){
                    marginEnd = autoSize(36)
                    topMargin = autoSize(30)
                }
            }.lparams(autoSize(225), autoSize(92))
        }.lparams(matchParent, autoSize(110))
    }

}