package cn.muchinfo.rma.view.base.procurement.detailsviewholder

import android.graphics.Typeface
import android.text.TextUtils
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.BusinessData
import cn.muchinfo.rma.global.isBlankNumber
import cn.muchinfo.rma.global.isBlankString
import cn.muchinfo.rma.global.isShowTimeString
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 cn.muchinfo.rma.view.base.home.contract.emptyView
import mtp.polymer.com.autowidget.adapter.BaseViewHolder
import org.jetbrains.anko.*

/**
 * 合同详情 点价/结算viewholder
 * @property activity AppCompatActivity
 * @property type String
 * @property itemSize IntArray
 * @constructor
 */
class PriceRecordViewHolder(private val activity: AppCompatActivity,private val type : String) : BaseViewHolder<BusinessData>(activity){
    override val itemSize: IntArray = intArrayOf(matchParent, wrapContent)

    override fun _FrameLayout.createContentView() {
        linearLayout {
            verticalLayout {
                gravity = Gravity.CENTER
                linearLayout {
                    /** 点价登记时间/结算审核时间 **/
                    textView {
                        data.bindOptional(context){
                            text = it?.applytime?.isShowTimeString("yyyyMM/dd HH:mm")
                        }
                        textColorInt = R.color.rma_black_33
                        textSizeAuto = 29
                        typeface = Typeface.defaultFromStyle(Typeface.BOLD)
                    }.lparams(wrapContent, wrapContent) {
                        marginStart = autoSize(35)
                        topMargin = autoSize(25)
                    }

                }.lparams(matchParent, wrapContent)
                /** 点价审核时间/结算审核时间 **/
                textView {
                    data.bindOptional(context){
                        text = it?.audittime?.isShowTimeString("yyyyMM/dd HH:mm")
                    }
                    textSizeAuto = 22
                    textColorInt = R.color.hint_text_color
                }.lparams(wrapContent, wrapContent){
                    marginStart = autoSize(35)
                    topMargin = autoSize(15)
                }

            }.lparams(autoSize(315), autoSize(120))

            verticalLayout {
                gravity = Gravity.CENTER
                /** 点价价格/结算项 **/
                textView {
                    data.bindOptional(context){
                        if (type == "1"){
                            text = it?.pricedPrice
                        }else{
                            text = it?.reckontype
                        }

                    }
                    textSizeAuto = 29
                    textColorInt = R.color.rma_black_33
                    maxLines = 1
                    ellipsize = TextUtils.TruncateAt.END
                }.lparams(wrapContent, wrapContent) {
                    topMargin = autoSize(25)
                }
                /** 升贴水/值 **/
                textView {
                    data.bindOptional(context){
                        if (type == "1"){
                            text = it?.pricemove
                        }else{
                            text = it?.reckonvalue
                        }

                    }
                    textSizeAuto = 22
                    textColorInt = R.color.hint_text_color
                }.lparams(wrapContent, wrapContent){
                    topMargin = autoSize(15)
                }

            }.lparams(autoSize(195), autoSize(120))

            /** 点价数量/申请人 **/
            verticalLayout {
                gravity = Gravity.CENTER
                textView {
                    data.bindOptional(context) {
                        if (type == "1"){
                            text = it?.pricedQty
                        }else{
                            text = it?.applyname?.isBlankString()
                        }
                    }
                    textSizeAuto = 29
                    textColorInt = R.color.rma_black_33
                    maxLines = 1
                    ellipsize = TextUtils.TruncateAt.END
                }.lparams(wrapContent, wrapContent) {
                    topMargin = autoSize(25)
                }
                /** 点价金额/审核人 **/
                textView {
                    data.bindOptional(context){
                        if (type == "1"){
                            text = it?.amount?.isBlankNumber()
                        }else{
                            text = it?.auditname?.isBlankString()
                        }
                    }
                    textSizeAuto = 22
                    textColorInt = R.color.hint_text_color
                }.lparams(wrapContent, wrapContent){
                    topMargin = autoSize(15)
                }
            }.lparams(autoSize(195), autoSize(120))

            verticalLayout {
                gravity = Gravity.CENTER
                /** 状态 */
                textView {
                    data.bindOptional(context){
                        if (type == "1"){
                            text = it?.applyname + "/" + it?.auditname
                        }else{
                            text = ViewEnumUtils.getBusinessManagementStatus(it?.applystatus ?: "")
                        }
                    }
                    textSizeAuto = 29
                    textColorInt = R.color.rma_black_33
                    maxLines = 1
                    ellipsize = TextUtils.TruncateAt.END
                }.lparams(wrapContent, wrapContent) {
                    topMargin = autoSize(25)
                }

                textView {
                    data.bindOptional(context){
                        if (type == "1"){
                            text = ViewEnumUtils.getBusinessManagementStatus(it?.applystatus ?: "")
                            visibility = View.VISIBLE
                        }else{
                            visibility = View.GONE
                        }
                    }
                    textSizeAuto = 29
                    textColorInt = R.color.rma_black_33
                    maxLines = 1
                    ellipsize = TextUtils.TruncateAt.END
                }.lparams(wrapContent, wrapContent)

            }.lparams(autoSize(195), autoSize(120))

        }.lparams(matchParent, autoSize(120))
    }

}