package com.adealink.weparty.profile.relation.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import com.adealink.frame.util.onClick
import com.adealink.weparty.commonui.recycleview.adapter.BindingViewHolder
import com.adealink.weparty.commonui.recycleview.adapter.multitype.ItemViewBinder
import com.adealink.weparty.module.profile.data.FollowStatus
import com.adealink.weparty.profile.R
import com.adealink.weparty.profile.databinding.ItemRelationshipFansBinding
import com.adealink.weparty.profile.relation.data.FansItemData


class FansItemViewBinder(val listener: OnFansItemClick) :
    ItemViewBinder<FansItemData, BindingViewHolder<ItemRelationshipFansBinding>>() {

    override fun onBindViewHolder(
        holder: BindingViewHolder<ItemRelationshipFansBinding>,
        item: FansItemData,
    ) {
        holder.binding.root.onClick {
            listener.goProfile(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)

        when (FollowStatus.map(item.data.followStatus)) {
            FollowStatus.NONE,
            FollowStatus.FANS -> {
                holder.binding.btnEachFollow.setImageResource(R.drawable.profile_each_follow_button_ic)
                holder.binding.btnEachFollow.onClick {
                    listener.follow(item, holder.layoutPosition)
                }
            }

            FollowStatus.FOLLOW,
            FollowStatus.EACH_FOLLOW -> {
                holder.binding.btnEachFollow.setImageResource(R.drawable.profile_each_unfollow_button_ic)
                holder.binding.btnEachFollow.onClick {
                    listener.unFollow(item, holder.layoutPosition)
                }
            }
        }
    }

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

    interface OnFansItemClick {
        fun follow(item: FansItemData, position: Int)
        fun unFollow(item: FansItemData, position: Int)

        fun goProfile(uid: String)
    }
}