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

import android.widget.ImageView
import android.widget.TextView
import coil.load
import coil.transform.RoundedCornersTransformation
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.cheng.blzb.R
import com.cheng.blzb.bean.MerchantGoodsEntity
import com.example.base.extensions.getColor
import com.example.base.utils.DensityUtils

class MyGoodsAdapter: BaseQuickAdapter<MerchantGoodsEntity, BaseViewHolder>(R.layout.listitem_my_goods) {

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

    override fun convert(holder: BaseViewHolder, item: MerchantGoodsEntity) {
        if (item.file.isNotEmpty()) {
            holder.getView<ImageView>(R.id.iv_cover).load(item.file[0].url){
                transformations(RoundedCornersTransformation(DensityUtils.dp2px(6f).toFloat()))
            }
        }
        holder.setText(R.id.tv_title, item.goods_name)
        holder.setText(R.id.tv_content, item.goods_description)
        holder.setText(R.id.tv_amount, if (item.goods_price_type == "1") "${item.goods_price_show}元" else item.goods_price_show)
        holder.setText(R.id.tv_area, item.city_name)

        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.remark}")
                holder.setVisible(R.id.tv_refuse_reason, true)
            }
        }
    }
}