package com.adealink.weparty.room.list.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.room.databinding.LayoutRoomListItemBinding
import com.adealink.weparty.room.list.data.RoomListItemData

class RoomItemViewBinder(val listener: OnRoomClickListener) :
    ItemViewBinder<RoomListItemData, BindingViewHolder<LayoutRoomListItemBinding>>() {

    @SuppressLint("SetTextI18n")
    override fun onBindViewHolder(
        holder: BindingViewHolder<LayoutRoomListItemBinding>,
        item: RoomListItemData,
    ) {
        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<LayoutRoomListItemBinding> {
        return BindingViewHolder(LayoutRoomListItemBinding.inflate(inflater, parent, false))
    }

    interface OnRoomClickListener {
        fun goRoom(roomInfo: RoomInfo)
    }

}