package com.atmob.keyboard_android.component.item

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.atmob.keyboard_android.R
import com.atmob.keyboard_android.ext.click
import com.atmob.keyboard_android.model.AiChatModel
import me.drakeet.multitype.ItemViewBinder

/**
 * AI生成内容的列表项
 */
class AiChatViewBinder(
    private val onItemClick: (item: AiChatModel) -> Unit
) : ItemViewBinder<AiChatModel, AiChatViewBinder.InnerViewHolder>() {
    override fun onCreateViewHolder(
        inflater: LayoutInflater,
        parent: ViewGroup
    ): InnerViewHolder {
        return InnerViewHolder(inflater.inflate(R.layout.item_ai_chat, parent, false))
    }

    override fun onBindViewHolder(
        holder: InnerViewHolder,
        item: AiChatModel
    ) {
        holder.vContent.apply {
            text = item.text
            // 选中
            if (item.isSelected) {
                setBackgroundResource(R.drawable.bg_ai_chat_selected)
            } else {
                // 未选中
                setBackgroundResource(R.drawable.bg_ai_chat_normal)
            }
        }
        holder.vContent.click {
            onItemClick.invoke(item)
        }
    }

    inner class InnerViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        val vContent: TextView = itemView.findViewById(R.id.content)
    }
}