package com.adealink.weparty.playmate.userpush.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import com.adealink.frame.aab.util.getCompatString
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.playmate.databinding.ItemUserPushBinding
import com.adealink.weparty.playmate.userpush.data.UserPushItemData
import com.adealink.weparty.R as APP_R


class UserPushItemViewBinder(
    val goProfile: (uid: String) -> Unit,
    val goSession: (uid: String) -> Unit
) : ItemViewBinder<UserPushItemData, BindingViewHolder<ItemUserPushBinding>>() {

    override fun onBindViewHolder(
        holder: BindingViewHolder<ItemUserPushBinding>,
        item: UserPushItemData,
    ) {
        holder.binding.root.onClick {
            goProfile.invoke(item.data.uid)
        }
        holder.binding.ivAvatar.setImageUrl(item.data.avatar)
        holder.binding.tvUserName.text = item.data.nickname
        holder.binding.vGender.setGender(item.data.gender)
        holder.binding.vGender.setAge(item.data.age)
        if (item.data.online) {
            holder.binding.vOnline.show()
            holder.binding.vOnline.onStart()
        } else {
            holder.binding.vOnline.gone()
            holder.binding.vOnline.onStop()
        }
        holder.binding.vNew.show(item.data.newRegister)
        holder.binding.btnChat.text = if (item.data.contacted) {
            getCompatString(APP_R.string.common_already_chat)
        } else {
            getCompatString(APP_R.string.common_chat)
        }
        holder.binding.btnChat.onClick {
            goSession.invoke(item.data.uid)
        }
    }

    override fun onCreateViewHolder(
        inflater: LayoutInflater,
        parent: ViewGroup,
    ): BindingViewHolder<ItemUserPushBinding> {
        return BindingViewHolder(
            ItemUserPushBinding.inflate(
                inflater,
                parent,
                false
            )
        )
    }
}