package com.adealink.weparty.country.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.country.data.CountryItemData
import com.adealink.weparty.databinding.LayoutSelectCountryDataBinding

class CountryItemViewBinder(
    private val onItemSelect: (item: CountryItemData) -> Unit
) : ItemViewBinder<CountryItemData, BindingViewHolder<LayoutSelectCountryDataBinding>>() {
    override fun onCreateViewHolder(
        inflater: LayoutInflater,
        parent: ViewGroup
    ): BindingViewHolder<LayoutSelectCountryDataBinding> {
        return BindingViewHolder(LayoutSelectCountryDataBinding.inflate(inflater, parent, false))
    }

    @SuppressLint("SetTextI18n")
    override fun onBindViewHolder(
        holder: BindingViewHolder<LayoutSelectCountryDataBinding>,
        item: CountryItemData
    ) {
        holder.binding.root.onClick {
            onItemSelect.invoke(item)
        }
        holder.binding.ivCountry.setImageUrl(item.data.icon)
        holder.binding.tvTitle.text = item.data.getDisplayName()
    }

}