package com.adealink.weparty.room.applymic.adapter

import android.annotation.SuppressLint
import android.view.LayoutInflater
import android.view.ViewGroup
import com.adealink.frame.util.onClick
import com.adealink.weparty.commonui.ext.gone
import com.adealink.weparty.commonui.ext.show
import com.adealink.weparty.commonui.recycleview.adapter.BindingViewHolder
import com.adealink.weparty.commonui.recycleview.adapter.multitype.ItemViewBinder
import com.adealink.weparty.module.profile.data.Gender
import com.adealink.weparty.room.applymic.data.ApplyMicItemData
import com.adealink.weparty.room.databinding.LayoutHostApplyMicListItemBinding
import com.adealink.weparty.util.timePass
import com.adealink.weparty.R as APP_R

class HostApplyMemberViewBinder(
    val onAvatarClick: (item: ApplyMicItemData, position: Int) -> Unit,
    val onAcceptClick: (item: ApplyMicItemData, position: Int) -> Unit
) : ItemViewBinder<ApplyMicItemData, BindingViewHolder<LayoutHostApplyMicListItemBinding>>() {
    override fun onCreateViewHolder(
        inflater: LayoutInflater,
        parent: ViewGroup
    ): BindingViewHolder<LayoutHostApplyMicListItemBinding> {
        return BindingViewHolder(LayoutHostApplyMicListItemBinding.inflate(inflater, parent, false))
    }

    @SuppressLint("SetTextI18n")
    override fun onBindViewHolder(
        holder: BindingViewHolder<LayoutHostApplyMicListItemBinding>,
        item: ApplyMicItemData
    ) {
        holder.binding.ivAvatar.onClick {
            onAvatarClick.invoke(item, holder.layoutPosition)
        }
        holder.binding.tvIndex.text = (holder.layoutPosition + 1).toString()
        holder.binding.ivAvatar.setImageUrl(item.data.user.avatar)
        holder.binding.tvName.text = item.data.user.nickName
        when (item.data.user.gender) {
            Gender.MALE.gender -> {
                holder.binding.vGender.show()
                holder.binding.vGender.setImageResource(APP_R.drawable.common_male_ic)
            }

            Gender.FEMALE.gender -> {
                holder.binding.vGender.show()
                holder.binding.vGender.setImageResource(APP_R.drawable.common_female_ic)
            }

            else -> {
                holder.binding.vGender.gone()
            }
        }
        holder.binding.tvTime.text = item.data.applyTime.timePass()
        holder.binding.btnAccept.onClick {
            onAcceptClick.invoke(item, holder.layoutPosition)
        }
    }

}