package com.adealink.weparty.playmate.findpartner.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.playmate.data.PlaymateCategoryData
import com.adealink.weparty.playmate.databinding.LayoutFindPartnerCategoryItemBinding
import com.adealink.weparty.ui.category.data.CategoryListItemData


class CategoryItemViewBinder(
    val listener: CategoryChooseListener
) :
    ItemViewBinder<CategoryListItemData, BindingViewHolder<LayoutFindPartnerCategoryItemBinding>>() {

    override fun onBindViewHolder(
        holder: BindingViewHolder<LayoutFindPartnerCategoryItemBinding>,
        item: CategoryListItemData,
    ) {
        holder.binding.root.onClick {
            listener.onChoose(item.data)
        }
        holder.binding.ivImg.setImageUrl(item.data.icon)
        holder.binding.tvName.text = item.data.name
    }

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

    interface CategoryChooseListener {
        fun onChoose(data: PlaymateCategoryData)
    }
}