package com.swago.room.ranklist

import com.bumptech.glide.Glide
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.swago.baseswago.cusview.SwagoLevelView
import com.swago.baseswago.model.live.RankListModel
import com.swago.baseswago.util.AppContext
import com.swago.baseswago.util.UserInfo
import com.swago.room.R
import de.hdodenhof.circleimageview.CircleImageView

/**
 *@date 2021/12/1 20:40
 *description:
 */
class RankListAdapter  : BaseQuickAdapter<RankListModel.ListBean, BaseViewHolder>(R.layout.item_rank_list, arrayListOf()) {

    override fun convert(helper: BaseViewHolder, item: RankListModel.ListBean) {
        helper.apply {
            val ivAvatar = itemView.findViewById<CircleImageView>(R.id.ivAvatar)
            Glide.with(itemView.context).load(item.user_head_img_url)
                .placeholder(R.mipmap.default_avatar)
                .error(R.mipmap.default_avatar).centerCrop().into(ivAvatar)

            val tvLevel = itemView.findViewById<SwagoLevelView>(R.id.tvLevel)
            tvLevel.setUserLevel(item.user_wealth_level.toInt())

            setText(R.id.tvName,item.user_name)
            setText(R.id.tvIncomeValue,item.total_coins)

            UserInfo.getUserInfo()?.let {
                when(it.user_type){
                    0 -> {
                        setImageResource(R.id.ivType,R.mipmap.icon_room_coin)
                    }

                    1 -> {
                        setImageResource(R.id.ivType,R.mipmap.icon_diamond)
                    }
                    else -> {
                        setImageResource(R.id.ivType,R.mipmap.icon_room_coin)
                    }
                }
            }

            when(layoutPosition){
                0 -> {
                    setBackgroundRes(R.id.tvPosition,R.mipmap.ranklist_one)
                    setText(R.id.tvPosition,"")
                }
                1 -> {
                    setBackgroundRes(R.id.tvPosition,R.mipmap.ranklist_two)
                    setText(R.id.tvPosition,"")
                }

                2 -> {
                    setBackgroundRes(R.id.tvPosition,R.mipmap.ranklist_three)
                    setText(R.id.tvPosition,"")
                }

                else -> {
                    setBackgroundRes(R.id.tvPosition,R.drawable.shape_white_20)
                    setText(R.id.tvPosition,"${layoutPosition+1}")
                }
            }
        }
    }
}