package com.gh.gamecenter.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.gh.gamecenter.common.utils.goneIf
import com.gh.gamecenter.databinding.ItemReportReasonBinding
import com.lightgame.adapter.BaseRecyclerAdapter

class ReportReasonAdapter(
    context: Context,
    val items: ArrayList<String>,
    val onItemClick: (String) -> Unit
) :
    BaseRecyclerAdapter<RecyclerView.ViewHolder>(context) {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
        return ReportReasonViewHolder(
            ItemReportReasonBinding.inflate(
                LayoutInflater.from(mContext),
                parent,
                false
            )
        )
    }

    override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
        if (holder is ReportReasonViewHolder) {
            val item = items[position]
            holder.binding.reasonTv.text = item
            holder.binding.reasonArrowIv.goneIf(item != "其他原因")
            holder.binding.root.setOnClickListener {
                onItemClick.invoke(item)
            }
        }
    }

    override fun getItemCount(): Int = items.size

    inner class ReportReasonViewHolder(val binding: ItemReportReasonBinding) :
        RecyclerView.ViewHolder(binding.root)
}

