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.AiKeyboardKeyModel
import me.drakeet.multitype.ItemViewBinder

/**
 * AI键盘按键条目
 */
class AiKeyboardKeyViewBinder(
    private val onItemClick: (item: AiKeyboardKeyModel) -> Unit
) :
    ItemViewBinder<AiKeyboardKeyModel, AiKeyboardKeyViewBinder.InnerViewHolder>() {
    override fun onCreateViewHolder(
        inflater: LayoutInflater,
        parent: ViewGroup
    ): InnerViewHolder {
        return InnerViewHolder(inflater.inflate(R.layout.item_ai_keyboard_key, parent, false))
    }

    override fun onBindViewHolder(
        holder: InnerViewHolder,
        item: AiKeyboardKeyModel
    ) {
        holder.vKeyText.text = item.text
        holder.vKeyText.click {
            onItemClick.invoke(item)
        }
    }

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