package com.cheng.blzb.ui.fragment.mine.account

import android.widget.ImageView
import coil.load
import coil.transform.CircleCropTransformation
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.AccountEntity
import com.cheng.blzb.manager.UserConfigManager
import com.example.base.extensions.getColor

class AccountAdapter : BaseQuickAdapter<AccountEntity, BaseViewHolder>(R.layout.listitem_account) {

    override fun convert(holder: BaseViewHolder, item: AccountEntity) {
        holder.getView<ImageView>(R.id.iv_avatar).load(item.avater) {
            transformations(CircleCropTransformation())
            placeholder(R.mipmap.ic_default_avatar)
            error(R.mipmap.ic_default_avatar)
        }

        if (item.vip_type == "1") {
            holder.setGone(R.id.iv_vip_tag, true)
        } else if (item.vip_type == "2" || item.vip_type == "3") {
            holder.setImageResource(R.id.iv_vip_tag, if (item.vip_type == "2") R.mipmap.ic_vip_tag1 else R.mipmap.ic_vip_tag2)
            holder.setGone(R.id.iv_vip_tag, false)
        } else if (item.vip_type == "12" || item.vip_type == "11") {
            holder.setImageResource(R.id.iv_vip_tag, if (item.vip_type == "12") R.mipmap.ic_vip_tag3 else R.mipmap.ic_vip_tag4)
            holder.setGone(R.id.iv_vip_tag, false)
        }

        holder.setVisible(R.id.tv_current_account, item.user_id == UserConfigManager.userInfo?.user_id)
        holder.setVisible(R.id.tv_change_account, item.user_id != UserConfigManager.userInfo?.user_id)
        holder.setVisible(R.id.tv_user_id_left, item.user_id != UserConfigManager.userInfo?.user_id)
        holder.setVisible(R.id.tv_user_id_right, item.user_id == UserConfigManager.userInfo?.user_id)

        holder.setBackgroundColor(
            R.id.layout_title,
            if (item.user_id == UserConfigManager.userInfo?.user_id) getColor(R.color.color_dce4f3) else getColor(R.color.color_f7ebe2)
        )

        holder.setText(R.id.tv_user_id_left, "ID：${item.user_id}")
        holder.setText(R.id.tv_user_id_right, "ID：${item.user_id}")

        holder.setText(R.id.tv_username, item.name)
        holder.setGone(R.id.iv_bind_wx, !item.bind.contains("weixin"))
        holder.setGone(R.id.iv_bind_phone, !item.bind.contains("phone"))
    }
}