package com.adealink.weparty.order.center.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.order.center.data.OrderSkillItem
import com.adealink.weparty.order.databinding.LayoutOrderCenterSkillsItemBinding

class OrderSkillItemViewBinder(
    private val onClick: (OrderSkillItem) -> Unit
) : ItemViewBinder<OrderSkillItem, BindingViewHolder<LayoutOrderCenterSkillsItemBinding>>() {

    override fun onBindViewHolder(
        holder: BindingViewHolder<LayoutOrderCenterSkillsItemBinding>,
        item: OrderSkillItem,
    ) {
        holder.binding.root.onClick {
            onClick.invoke(item)
        }
        holder.binding.ivIcon.setImageUrl(item.data.categoryIcon)
        holder.binding.tvTitle.text = item.data.categoryName
        holder.binding.vPrice.setPrice(item.data.price, item.data.unit)
    }

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