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.SpotReportData
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.contract.emptyView
import mtp.polymer.com.autowidget.adapter.BaseViewHolder
import org.jetbrains.anko.*

/**
 * 现货报表列表viewholder
 * @property activity AppCompatActivity
 * @property viewModel ReportQueryViewModel
 * @property itemSize IntArray
 * @constructor
 */
class SpotReportViewHolder(
    private val activity: AppCompatActivity,
    private val viewModel: ReportQueryViewModel
) : BaseViewHolder<SpotReportData>(activity) {
    override val itemSize: IntArray = intArrayOf(matchParent, wrapContent)

    @SuppressLint("SetTextI18n")
    override fun _FrameLayout.createContentView() {

        verticalLayout {
            onThrottleFirstClick {
                viewModel.resetDataList(index = dataIndex)
            }
            data.bindOptional(context) {
                if (it?.indexSelect == 0) {
                    backgroundResource = R.color.white
                } else if (it?.indexSelect == 1) {
                    backgroundResource = R.color.rma_list_select_color
                }
            }
            linearLayout {
                verticalLayout {
                    gravity = Gravity.START
                    textView {
                        data.bindOptional(context) {
                            text = it?.wrstandardname
                        }
                        textSizeAuto = 24
                        textColorInt = R.color.hint_text_color
                    }.lparams(wrapContent, wrapContent) {
                        marginStart = autoSize(36)
                        topMargin = autoSize(15)
                    }
                }.lparams(autoSize(225), autoSize(100))

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

                    textView {
                        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) {
                            text = it?.todaybuyreckonqty + it?.enumdicname
                        }
                        textSizeAuto = 24
                        textColorInt = R.color.hint_text_color
                    }.lparams(wrapContent, wrapContent)

                    textView {
                        data.bindOptional(context) {
                            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 {
                        text = "--"
                        textSizeAuto = 24
                        textColorInt = R.color.hint_text_color
                    }.lparams(wrapContent, wrapContent) {
                        marginEnd = autoSize(36)
                        topMargin = autoSize(15)
                    }

                    textView {
                        text = "--"
                        textSizeAuto = 24
                        textColorInt = R.color.hint_text_color
                    }.lparams(wrapContent, wrapContent) {
                        marginEnd = autoSize(36)
                    }
                }.lparams(autoSize(225), autoSize(97))
            }.lparams(matchParent, autoSize(100))
            linearLayout {
                emptyView()

                textView {
                    onThrottleFirstClick {

                    }
                    backgroundResource = R.drawable.rma_item_click_bg
                    gravity = Gravity.CENTER
                    textResource = R.string.details
                    textColorInt = R.color.rma_item_click_color
                    textSizeAuto = 26
                }.lparams(autoSize(120), autoSize(48)) {
                    marginEnd = autoSize(36)
                }
            }.lparams(matchParent, autoSize(72))
        }.lparams(matchParent, wrapContent)
    }

}