package com.bc_chat.contacts.adapter

import android.content.Context
import com.bc_chat.bc_base.adapter.ModeListAdapter
import com.bc_chat.bc_base.entity.ListModel
import com.bc_chat.bc_base.entity.group.MemberBean
import com.bc_chat.bc_base.utils.gone
import com.bc_chat.bc_base.utils.visible
import com.bc_chat.contacts.R
import com.bc_chat.contacts.databinding.ItemLayoutMemberBinding
import com.zhaohaoting.framework.utils.glid.GlideUtils

/**
 * author：Created by zhaohaoting on 2019/2/27
 * email：526309416@qq.com
 * desc：群联系人
 */
class GroupContactListAdapter constructor(context: Context, var from: String? = FROM_GROUP_INFO) : ModeListAdapter<MemberBean, ListModel<MemberBean>>(context, ListModel()) {

    companion object {
        const val FROM_GROUP_INFO = "GroupInfo"
        const val FROM_SET_GROUP_ADMIN = "SetGroupAdmin"
    }

    override fun getItemLayoutId(type: Int): Int = R.layout.item_layout_member

    override fun isEmpty(): Boolean {
        return if (from.equals("GroupInfo")) {
            false
        } else {
            super.isEmpty()
        }
    }

    override fun onBindViewHolderHF(baseViewHolder: BaseViewHolder<*>?, realPosition: Int, data: MemberBean?) {
        val dataBinding = baseViewHolder?.dataBinding as ItemLayoutMemberBinding
        dataBinding.tvName.text = data?.remark ?: data?.nickname
        GlideUtils.loadCircleImage(context, data?.photo, dataBinding.ivHeader)
        when (data?.type) {
            1 -> {
                dataBinding.tvRole.setBackgroundResource(R.drawable.shape_lord_tag_bg)
                dataBinding.tvRole.text = "群主"
                dataBinding.tvRole.visible()
            }
            2 -> {
                dataBinding.tvRole.setBackgroundResource(R.drawable.shape_admin_tag_bg)
                dataBinding.tvRole.text = "管理"
                dataBinding.tvRole.visible()
            }
            else -> {
                dataBinding.tvRole.gone()
            }
        }
    }
}
