package com.gh.gamecenter.gamedetail.dialog

import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.gh.gamecenter.R
import com.gh.gamecenter.entity.TagStyleEntity
import com.lightgame.adapter.BaseRecyclerAdapter

class GameTagsAdapter(context: Context, private val tags: ArrayList<TagStyleEntity>) :
    BaseRecyclerAdapter<RecyclerView.ViewHolder>(context) {

    var onClickListener: ((tagEntity: TagStyleEntity) -> Unit)? = null
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
        val view = LayoutInflater.from(mContext).inflate(R.layout.item_game_detail_game_tag, parent, false)
        return object : RecyclerView.ViewHolder(view) {}
    }

    override fun getItemCount(): Int = tags.size

    override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
        val tagEntity = tags[position]
        holder.itemView.apply {
            // 就一个简单的文字列表弹窗，就不麻烦去用 ViewBinding 了
            findViewById<TextView>(R.id.tagNameTv).text = tagEntity.name
            setOnClickListener {
                onClickListener?.invoke(tagEntity)
            }
        }
    }

}