package com.zj365.mime.adapter

import android.annotation.SuppressLint
import android.text.TextUtils
import android.widget.TextView
import androidx.core.view.isVisible
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.xty.base.adapter.BaseAdapter
import com.xty.common.SizeUtil
import com.zj365.mime.R
import com.zj365.mime.act.MyIntegralAct
import com.xty.network.model.MyIntegralBean

class MyIntegralAdapter : BaseAdapter<MyIntegralBean>(R.layout.item_my_integral) {

    @SuppressLint("SetTextI18n")
    override fun convert(holder: BaseViewHolder, item: MyIntegralBean) {
        //积分类型名称
        val integralTypeName = holder.getView<TextView>(R.id.tvIntegralTypeName)
        //积分获取数量
        val integralGetNumber = holder.getView<TextView>(R.id.tvIntegralGetNumber)
        //积分数量
        val integralNumber = holder.getView<TextView>(R.id.tvIntegralNumber)
        //积分状态
        val integralStatus = holder.getView<TextView>(R.id.tvIntegralStatus)
        //积分描述
        val integralInfo = holder.getView<TextView>(R.id.tvIntegralInfo)

        integralTypeName.text = item.typeName
        if (item.type == 9) {
            integralGetNumber.text = "(累计获得${item.count}次)"
            integralGetNumber.isVisible = true
            integralStatus.isVisible = false
        } else {
            integralGetNumber.isVisible = false
            integralStatus.isVisible = true
        }
        val myIntegralAct = context as MyIntegralAct
        if (myIntegralAct.user != null && item.type == 4) {
            val actTime = myIntegralAct.user!!.actTime
            integralStatus.isVisible = !TextUtils.isEmpty(actTime)
        }

        if (item.type != 16) {
            integralNumber.text = "+${item.num}积分"
        } else {
            integralNumber.text = "最高+${item.num}积分/次"
        }

        if (data.size - 1 == getItemPosition(item)) {
            holder.setGone(R.id.line, true)
        }

        if (item.status == 0) {
            integralStatus.isEnabled = true
            if (item.type != 16) {
                integralStatus.text = "去完成"
            } else {
                integralStatus.text = "去邀请"
            }
            integralStatus.setBackgroundResource(R.drawable.shape_integral_status)
            integralStatus.setTextColor(context.getColor(R.color.col_02c))
        } else {
            integralStatus.isEnabled = false
            integralStatus.text = "已完成"
            integralStatus.setBackgroundResource(R.drawable.shape_integral_status_no)
            integralStatus.setTextColor(context.getColor(R.color.col_6B6))
        }
        integralStatus.setPadding(
            SizeUtil.dp2px(context, 11f),
            SizeUtil.dp2px(context, 5f),
            SizeUtil.dp2px(context, 11f),
            SizeUtil.dp2px(context, 5f)
        )

        integralInfo.text = if (!TextUtils.isEmpty(item.info)) {
            item.info
        } else {
            ""
        }
    }
}