package com.adealink.weparty.ui.category.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.R
import com.adealink.weparty.commonui.recycleview.adapter.BindingViewHolder
import com.adealink.weparty.commonui.recycleview.adapter.multitype.ItemViewBinder
import com.adealink.weparty.databinding.LayoutCategoryTabTitleBinding
import com.adealink.weparty.ui.category.data.CategoryListTitleData

class CategoryTabTitleViewBinder(
    val onTabSelected: (item: CategoryListTitleData, position: Int) -> Unit
) : ItemViewBinder<CategoryListTitleData, BindingViewHolder<LayoutCategoryTabTitleBinding>>() {

    override fun onBindViewHolder(
        holder: BindingViewHolder<LayoutCategoryTabTitleBinding>,
        item: CategoryListTitleData,
    ) {
        holder.binding.root.onClick {
            onTabSelected.invoke(item, holder.layoutPosition)
        }
        holder.binding.tvTitle.text = item.data.name
        if (item.selected) {
            holder.binding.clContent.setBackgroundResource(R.drawable.category_tab_item_bg)
            holder.binding.tvTitle.setTextColor(getCompatColor(R.color.white))
        } else {
            holder.binding.clContent.setBackgroundResource(0)
            holder.binding.tvTitle.setTextColor(getCompatColor(R.color.color_FF4E5969))
        }
    }

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