package com.adealink.weparty.profile.search.adapter

import android.annotation.SuppressLint
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.room.data.RoomInfo
import com.adealink.weparty.profile.databinding.LayoutProfileSearchRoomItemBinding
import com.adealink.weparty.profile.search.data.SearchRoomResultItemData

class SearchRoomItemViewBinder(val listener: OnRoomResultClickListener) :
    ItemViewBinder<SearchRoomResultItemData, BindingViewHolder<LayoutProfileSearchRoomItemBinding>>() {

    @SuppressLint("SetTextI18n")
    override fun onBindViewHolder(
        holder: BindingViewHolder<LayoutProfileSearchRoomItemBinding>,
        item: SearchRoomResultItemData,
    ) {
        holder.binding.root.onClick {
            listener.goRoom(item.data)
        }
        holder.binding.ivCover.setImageUrl(item.data.roomCover)
        holder.binding.tvRoomId.text = "ID ${item.data.roomId}"

        holder.binding.tvRoomName.text = item.data.roomTitle
        holder.binding.tvOwnerName.text = item.data.owner.nickName
    }

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

    interface OnRoomResultClickListener {
        fun goRoom(roomInfo: RoomInfo)
    }

}