package com.adealink.weparty.module.widget.form.dialog

import android.view.LayoutInflater
import android.view.ViewGroup
import com.adealink.frame.aab.util.getCompatColor
import com.adealink.frame.util.onClick
import com.adealink.weparty.commonui.DEFAULT_FONT_BOLD
import com.adealink.weparty.commonui.DEFAULT_FONT_REGULAR
import com.adealink.weparty.commonui.recycleview.adapter.BindingViewHolder
import com.adealink.weparty.commonui.recycleview.adapter.multitype.ItemViewBinder
import com.adealink.weparty.databinding.WidgetDialogChooseItemBinding
import com.adealink.weparty.R as APP_R

class ChoiceItemViewBinder(
    val onSelect: (ChooseItem, Int) -> Unit
) : ItemViewBinder<ChooseItem, BindingViewHolder<WidgetDialogChooseItemBinding>>() {

    override fun onBindViewHolder(
        holder: BindingViewHolder<WidgetDialogChooseItemBinding>,
        item: ChooseItem,
    ) {
        holder.binding.root.onClick {
            onSelect.invoke(item, holder.layoutPosition)
        }
        holder.binding.tvText.text = item.getDisplayName()
        if (item.selected) {
            holder.binding.tvText.setBackgroundResource(APP_R.drawable.common_widget_multiple_choice_selected_bg)
            holder.binding.tvText.setTextColor(getCompatColor(APP_R.color.color_FF3FBFBD))
            holder.binding.tvText.typeface = DEFAULT_FONT_BOLD
        } else {
            holder.binding.tvText.setBackgroundResource(APP_R.drawable.common_widget_multiple_choice_bg)
            holder.binding.tvText.setTextColor(getCompatColor(APP_R.color.color_FF1D2129))
            holder.binding.tvText.typeface = DEFAULT_FONT_REGULAR
        }
    }

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