package com.cheng.blzb.ui.fragment.bid.publish.bid

import android.text.TextUtils
import android.widget.TextView
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.cheng.blzb.R
import com.cheng.blzb.bean.BidDetailEntity
import com.cheng.blzb.utils.BidTypeUtils
import com.cheng.blzb.utils.StringUtils
import com.cheng.blzb.widget.CommonShapeView
import com.example.base.extensions.getColor
import com.example.base.ui.list.LoadMoreAdapter

class MyBidAdapter : LoadMoreAdapter<BidDetailEntity>(R.layout.listitem_my_bid) {

    init {
        addChildClickViewIds(R.id.btn_delete, R.id.btn_edit, R.id.btn_view)
    }

    override fun convert(holder: BaseViewHolder, item: BidDetailEntity) {
        val tvTag = holder.getView<CommonShapeView>(R.id.tv_tag)
        tvTag.setBgColor(BidTypeUtils.getTypeColor(item.type_name))
        tvTag.text = BidTypeUtils.getShortName(item.type_name)

        holder.setText(R.id.tv_title, item.origin_title)
        holder.setText(R.id.tv_location, if (TextUtils.isEmpty(item.city_name)) "全国" else item.city_name)
        holder.setText(R.id.tv_amount, StringUtils.formatAmount(item.project_amount))
        holder.setText(R.id.tv_time, item.tips_time)

        holder.setGone(R.id.tv_refuse_reason, true)
        when (item.status) {
            "1" -> {
                holder.setText(R.id.tv_status, "待审核")
                holder.setTextColor(R.id.tv_status, getColor(R.color.color_ff9234))
                holder.setBackgroundResource(R.id.tv_status, R.drawable.shape_publish_status_bg1)
                holder.getView<TextView>(R.id.tv_status).setCompoundDrawablesWithIntrinsicBounds(R.mipmap.ic_publish_status1, 0, 0, 0)
            }

            "2" -> {
                holder.setText(R.id.tv_status, "已发布")
                holder.setTextColor(R.id.tv_status, getColor(R.color.color_3bbf0f))
                holder.setBackgroundResource(R.id.tv_status, R.drawable.shape_publish_status_bg2)
                holder.getView<TextView>(R.id.tv_status).setCompoundDrawablesWithIntrinsicBounds(R.mipmap.ic_publish_status2, 0, 0, 0)
            }

            "3" -> {
                holder.setText(R.id.tv_status, "已驳回")
                holder.setTextColor(R.id.tv_status, getColor(R.color.color_ff592b))
                holder.setBackgroundResource(R.id.tv_status, R.drawable.shape_publish_status_bg3)
                holder.getView<TextView>(R.id.tv_status).setCompoundDrawablesWithIntrinsicBounds(R.mipmap.ic_publish_status3, 0, 0, 0)

                holder.setText(R.id.tv_refuse_reason, "理由：${item.review_remark}")
                holder.setVisible(R.id.tv_refuse_reason, true)
            }
        }

        holder.setGone(R.id.tv_location, TextUtils.isEmpty(item.city_name))
        holder.setGone(R.id.tv_amount, TextUtils.isEmpty(item.project_amount))
        holder.setGone(R.id.tv_time, TextUtils.isEmpty(item.tips_time))
    }
}