package com.adealink.weparty.profile.edit.dialog.adapter

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.profile.R
import com.adealink.weparty.profile.databinding.LayoutEditProfileInterestListItemBinding
import com.adealink.weparty.ui.category.data.CategoryListItemData
import com.adealink.weparty.R as APP_R

class InterestItemViewBinder(
    val onSelect: (item: CategoryListItemData, position: Int) -> Unit
) : ItemViewBinder<CategoryListItemData, BindingViewHolder<LayoutEditProfileInterestListItemBinding>>() {

    override fun onBindViewHolder(
        holder: BindingViewHolder<LayoutEditProfileInterestListItemBinding>,
        item: CategoryListItemData,
    ) {
        holder.binding.root.onClick {
            onSelect.invoke(item, holder.layoutPosition)
        }
        holder.binding.root.text = item.data.name
        if (item.selected) {
            holder.binding.root.setBackgroundResource(R.drawable.profile_edit_interest_item_selected_bg)
            holder.binding.root.setTextColor(getCompatColor(APP_R.color.color_FF3FBFBD))
            holder.binding.root.typeface = DEFAULT_FONT_BOLD
        } else {
            holder.binding.root.setBackgroundResource(R.drawable.profile_edit_interest_item_bg)
            holder.binding.root.setTextColor(getCompatColor(APP_R.color.color_CC1D2129))
            holder.binding.root.typeface = DEFAULT_FONT_REGULAR
        }
    }

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

}