package com.adealink.weparty.profile.search.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.profile.databinding.LayoutProfileSearchHistoryItemBinding
import com.adealink.weparty.profile.search.data.SearchHistoryItemData

class SearchHistoryViewBinder(val listener: OnHistoryClickListener) :
    ItemViewBinder<SearchHistoryItemData, BindingViewHolder<LayoutProfileSearchHistoryItemBinding>>() {

    override fun onBindViewHolder(
        holder: BindingViewHolder<LayoutProfileSearchHistoryItemBinding>,
        item: SearchHistoryItemData,
    ) {
        holder.binding.root.onClick {
            listener.onClick(item, holder.layoutPosition)
        }
        holder.binding.tvKeyword.text = item.keyword
    }

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

    interface OnHistoryClickListener {
        fun onClick(item: SearchHistoryItemData, pos: Int)
    }

}