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

import android.content.Intent
import android.view.Gravity
import androidx.fragment.app.Fragment
import cn.muchinfo.rma.R
import cn.muchinfo.rma.global.data.NumberSpotData
import cn.muchinfo.rma.lifecycle.bindOptional
import cn.muchinfo.rma.view.autoWidget.autoSize
import cn.muchinfo.rma.view.autoWidget.onThrottleFirstClick
import cn.muchinfo.rma.view.autoWidget.textColorInt
import cn.muchinfo.rma.view.autoWidget.textSizeAuto
import cn.muchinfo.rma.view.base.home.HomeViewModel
import com.blankj.utilcode.util.ActivityUtils
import mtp.polymer.com.autowidget.adapter.BaseViewHolder
import org.jetbrains.anko.*

/**
 * 敞口-现货数量 / 期货数量viewholder
 * @property baseFragment Fragment
 * @property viewModel ExposureViewModel
 * @property type String type 1 ： 现货 2 ：期货
 * @property itemSize IntArray
 * @constructor
 */
class ExposureNumberViewHolder(
    private val baseFragment: Fragment,
    private val viewModel: ExposureViewModel,
    private val type : String
): BaseViewHolder<NumberSpotData>(baseFragment.context!!) {
    override val itemSize: IntArray = intArrayOf(matchParent, autoSize(110))

    override fun _FrameLayout.createContentView() {
         linearLayout {
             onThrottleFirstClick {
                 val intent = Intent()
                 intent.putExtra("type",type)
                 intent.putExtra("data",data.value)
                 intent.setClass(context,NumberExposureDetailsActivity::class.java)
                 ActivityUtils.startActivity(intent)
             }
             verticalLayout {
                gravity = Gravity.LEFT
                 textView {
                     data.bindOptional(context){
                         text = if (type == "1"){
                             it?.wrstandardname
                         }else{
                             it?.goodsname
                         }
                     }
                     textSizeAuto = 31
                     textColorInt = R.color.rma_black_33
                 }.lparams(wrapContent, wrapContent){
                     marginStart = autoSize(36)
                     topMargin = autoSize(10)
                 }
                 textView {
                     data.bindOptional(context){
                         text = if (type == "1"){
                             it?.wrstandardcode
                         }else{
                             it?.goodscode
                         }
                     }
                     textSizeAuto = 31
                     textColorInt = R.color.rma_black_33
                 }.lparams(wrapContent, wrapContent){
                     marginStart = autoSize(36)
                 }
             }.lparams(autoSize(225), autoSize(110))

             verticalLayout {
                 gravity = Gravity.CENTER
                textView {
                    data.bindOptional(context){
                        text = if (type == "1"){
                            it?.oritoalspotqty
                        }else{
                            it?.totalydqty + "手"
                        }
                     }
                    textSizeAuto = 31
                    textColorInt = R.color.rma_black_33
                }.lparams(wrapContent, wrapContent)
             }.lparams(autoSize(225), autoSize(110))

             verticalLayout {
                 gravity = Gravity.CENTER
                textView {
                    data.bindOptional(context){
                        text = if (type == "1"){
                            it?.increaseqty
                        }else{
                            it?.increaseqty + "手"
                        }
                     }
                    textSizeAuto = 31
                    textColorInt = R.color.rma_black_33
                }.lparams(wrapContent, wrapContent)
                 textView {
                      data.bindOptional(context){
                        text = if (type == "1"){
                            it?.decreaseqty
                        }else{
                            it?.decreaseqty + "手"
                        }
                     }
                     textSizeAuto = 31
                     textColorInt = R.color.rma_black_33
                 }.lparams(wrapContent, wrapContent)
             }.lparams(autoSize(225), autoSize(110))

             verticalLayout {
                 gravity = Gravity.RIGHT
                 textView {
                     data.bindOptional(context){
                        text = if (type == "1"){
                            it?.totalspotqty
                        }else{
                            it?.totalcurqty + "手"
                        }
                     }
                     textSizeAuto = 31
                     textColorInt = R.color.rma_black_33
                 }.lparams(wrapContent, wrapContent){
                     marginEnd = autoSize(36)
                     topMargin = autoSize(30)
                 }
             }.lparams(autoSize(225), autoSize(110))
         }
    }

}