package com.adealink.weparty.playmate.findpartner.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.playmate.R
import com.adealink.weparty.playmate.databinding.LayoutFindPartnerOptionItemBinding
import com.adealink.weparty.playmate.findpartner.data.OptionItemData
import com.adealink.weparty.R as APP_R

class OptionItemViewBinder(val listener: OnOptionsSelectListener) :
    ItemViewBinder<OptionItemData, BindingViewHolder<LayoutFindPartnerOptionItemBinding>>() {

    override fun onBindViewHolder(
        holder: BindingViewHolder<LayoutFindPartnerOptionItemBinding>,
        item: OptionItemData,
    ) {
        holder.binding.tvOption.text = item.data.option
        if (item.data.selected) {
            holder.binding.tvOption.setBackgroundResource(R.drawable.find_partner_option_item_selected_bg)
            holder.binding.tvOption.setTextColor(getCompatColor(APP_R.color.color_FF3FBFBD))
            holder.binding.tvOption.typeface = DEFAULT_FONT_BOLD
        } else {
            holder.binding.tvOption.setBackgroundResource(R.drawable.find_partner_option_item_bg)
            holder.binding.tvOption.setTextColor(getCompatColor(APP_R.color.color_FF4E5969))
            holder.binding.tvOption.typeface = DEFAULT_FONT_REGULAR
        }
        holder.binding.root.onClick {
            listener.onSelected(item)
        }
    }

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

    interface OnOptionsSelectListener {
        fun onSelected(option: OptionItemData)
    }
}