package com.adealink.weparty.playmate.detail.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import com.adealink.frame.aab.util.getCompatString
import com.adealink.frame.util.onClick
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.ItemPlaymateDetailCommentTitleBinding
import com.adealink.weparty.playmate.detail.data.PlaymateDetailCommentTitleItemData
import com.adealink.weparty.util.formatStar

class PlaymateDetailCommentTitleViewBinder(
    val onMoreClick: () -> Unit
) : ItemViewBinder<PlaymateDetailCommentTitleItemData, BindingViewHolder<ItemPlaymateDetailCommentTitleBinding>>() {

    override fun onBindViewHolder(
        holder: BindingViewHolder<ItemPlaymateDetailCommentTitleBinding>,
        item: PlaymateDetailCommentTitleItemData,
    ) {
        holder.binding.tvEvaluate.text = formatStar(item.star)
        holder.binding.tvCommentCount.text =
            getCompatString(R.string.playmate_detail_comment_count, item.commentCount.toString())
        holder.binding.tvMore.onClick {
            onMoreClick.invoke()
        }
    }

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

}