package cn.muchinfo.rma.view.autoWidget.dialog

import android.view.Gravity
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import cn.muchinfo.rma.R
import cn.muchinfo.rma.global.data.AccountData
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.app.Constant
import cn.muchinfo.rma.view.base.home.contract.emptyView
import com.blankj.utilcode.util.SPUtils
import mtp.polymer.com.autowidget.adapter.BaseViewHolder
import org.jetbrains.anko.*

class AccountViewHolder(private val activity: AppCompatActivity) : BaseViewHolder<AccountData>(activity){
    override val itemSize: IntArray = intArrayOf(matchParent, wrapContent)

    override fun _FrameLayout.createContentView() {
        linearLayout {
            gravity = Gravity.CENTER_VERTICAL

            linearLayout {
                gravity = Gravity.CENTER
                backgroundResource = R.drawable.main_cercle_red_bg
                textView {
                    text = "李"
                    textColorInt = R.color.white
                    textSizeAuto = 31
                }
            }.lparams(autoSize(72), autoSize(72)){
                marginStart = autoSize(52)
            }

            verticalLayout {
                textView {
                    text = "李四"
                    textSizeAuto = 34
                    textColorInt = R.color.rma_black_33
                }.lparams(wrapContent, wrapContent){
                    topMargin = autoSize(30)
                }

                textView {
                    text = "213124214"
                    textSizeAuto = 29
                    textColorInt = R.color.rma_gray_color
                }.lparams(wrapContent, wrapContent)
            }.lparams(wrapContent, autoSize(140)){
                marginStart = autoSize(35)
            }

            emptyView()

            imageView {
                data.bindOptional(context){
                    if (it?.accountid == SPUtils.getInstance().getLong(Constant.SELECT_ACCOUNT_ID)){
                        visibility = View.VISIBLE
                    }else{
                        visibility = View.GONE
                    }
                }
                imageResource = R.mipmap.rma_account_select
            }.lparams(autoSize(36), autoSize(36)){
                marginEnd = autoSize(50)
            }

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

}