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

import android.view.Gravity
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import cn.muchinfo.rma.R
import cn.muchinfo.rma.global.ViewEnumUtils
import cn.muchinfo.rma.global.data.SpotReportData
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.*

class SpotReportDetailsViewHolder(
    private val activity: AppCompatActivity, private val viewModel: ReportQueryViewModel,private val type : String
) : BaseViewHolder<SpotReportData>(activity){
    override val itemSize: IntArray = intArrayOf(matchParent, wrapContent)

    override fun _FrameLayout.createContentView() {
        linearLayout {
            verticalLayout {
                gravity = Gravity.START
                textView {
                    data.bindOptional(context){
                        if (type == "1"){
                            text = it?.logdatetime
                        }else{
                            text = it?.reckondate
                        }
                    }
                    textSizeAuto = 24
                    textColorInt = R.color.hint_text_color
                }.lparams(wrapContent, wrapContent){
                    marginStart = autoSize(36)
                    topMargin = autoSize(15)
                }

                textView {
                    visibility = if (type == "2"){
                        View.GONE
                    }else{
                        View.VISIBLE
                    }
                    data.bindOptional(context){
                        text = it?.totalsellpricedqty + it?.enumdicname
                    }
                    textSizeAuto = 24
                    textColorInt = R.color.hint_text_color
                }.lparams(wrapContent, wrapContent)
            }.lparams(autoSize(225), autoSize(100))

            verticalLayout {
                gravity = Gravity.CENTER
                textView {
                    data.bindOptional(context){
                        if (type == "1"){
                            text = ViewEnumUtils.getContractType(it?.logtypename ?: "")
                        }else{
                            text = it?.totalbuypricedqty + it?.enumdicname
                        }
                    }
                    textSizeAuto = 24
                    textColorInt = R.color.hint_text_color
                }.lparams(wrapContent, wrapContent)

                textView {
                    data.bindOptional(context){
                        if (type == "1"){
                            text = it?.relatedno
                        }else{
                            text = it?.totalsellpricedqty + it?.enumdicname
                        }
                    }
                    textSizeAuto = 24
                    textColorInt = R.color.hint_text_color
                }.lparams(wrapContent, wrapContent)
            }.lparams(autoSize(225), autoSize(100))

            verticalLayout {
                gravity = Gravity.CENTER
                textView {
                    data.bindOptional(context){
                        if (type == "1"){
                            text = it?.logtypename
                        }else{
                            text = it?.todaybuyreckonqty + it?.enumdicname
                        }
                    }
                    textSizeAuto = 24
                    textColorInt = R.color.hint_text_color
                }.lparams(wrapContent, wrapContent)

                textView {
                    data.bindOptional(context){
                        if (type == "1"){
                            text = it?.logvalue
                        }else{
                            text = it?.todaysellreckonqty + it?.enumdicname
                        }
                    }
                    textSizeAuto = 24
                    textColorInt = R.color.hint_text_color
                }.lparams(wrapContent, wrapContent)
            }.lparams(autoSize(225), autoSize(97))

            verticalLayout {
                gravity = Gravity.END
                textView {
                    data.bindOptional(context){
                        if (type == "1"){
                            text = it?.applyname
                        }else{
                            text = "--"
                        }
                    }
                    textSizeAuto = 24
                    textColorInt = R.color.hint_text_color
                }.lparams(wrapContent, wrapContent){
                    marginEnd = autoSize(36)
                    topMargin = autoSize(15)
                }

                textView {
                    data.bindOptional(context){
                        if (type == "1"){
                            text = it?.applyname
                        }else{
                            text = "--"
                        }
                    }
                    visibility = if (type == "1"){
                        View.GONE
                    }else{
                        View.VISIBLE
                    }

                    textSizeAuto = 24
                    textColorInt = R.color.hint_text_color
                }.lparams(wrapContent, wrapContent){
                    marginEnd = autoSize(36)
                }
            }.lparams(autoSize(225), autoSize(97))
        }.lparams(matchParent, autoSize(100))
    }

}