package com.adealink.weparty.profile.ui.about.adapter

import android.annotation.SuppressLint
import android.view.LayoutInflater
import android.view.ViewGroup
import com.adealink.frame.util.onClick
import com.adealink.weparty.commonui.ext.gone
import com.adealink.weparty.commonui.ext.show
import com.adealink.weparty.commonui.recycleview.adapter.BindingViewHolder
import com.adealink.weparty.commonui.recycleview.adapter.multitype.ItemViewBinder
import com.adealink.weparty.module.profile.data.UserPlaymateSkill
import com.adealink.weparty.profile.databinding.LayoutProfileSkillItemBinding
import com.adealink.weparty.util.formatNumberStr

data class SkillItemData(
    val data: UserPlaymateSkill
)

class SKillViewBinder(
    val isSelf: () -> Boolean,
    val order: (item: UserPlaymateSkill) -> Unit
) :
    ItemViewBinder<SkillItemData, BindingViewHolder<LayoutProfileSkillItemBinding>>() {

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

    @SuppressLint("SetTextI18n")
    override fun onBindViewHolder(
        holder: BindingViewHolder<LayoutProfileSkillItemBinding>,
        item: SkillItemData
    ) {
        holder.binding.ivBg.setImageUrl(item.data.cover)
        holder.binding.ivIcon.setImageUrl(item.data.icon)
        holder.binding.tvTitle.text = item.data.name
        holder.binding.tvDesc.text = "${formatNumberStr(item.data.price, omitted = false)}/${item.data.unit}"
        holder.binding.root.onClick {
            order.invoke(item.data)
        }
        if (isSelf()) {
            holder.binding.btnOrder.gone()
        } else {
            holder.binding.btnOrder.show()
        }
    }

}