package com.gh.gamecenter.feedback.view.suggest

import android.content.Context
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.gh.gamecenter.common.base.BaseRecyclerViewHolder
import com.gh.gamecenter.common.utils.goneIf
import com.gh.gamecenter.common.utils.toBinding
import com.gh.gamecenter.feedback.databinding.LayoutOptionPopupItemBinding
import com.lightgame.adapter.BaseRecyclerAdapter

class OptionPopupAdapter(
    context: Context,
    private var mOptionList: List<String> = emptyList(),
    private val mAction: (text: String) -> Unit
) :
    BaseRecyclerAdapter<RecyclerView.ViewHolder>(context) {

    fun setListData(data: ArrayList<String>) {
        mOptionList = data
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
        return OptionPopupItemViewHolder(parent.toBinding())
    }

    override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
        if (holder is OptionPopupItemViewHolder) {
            holder.binding.titleTv.text = mOptionList[position]
            holder.binding.titleTv.setOnClickListener { mAction.invoke(mOptionList[position]) }
            holder.binding.divider.goneIf(position == itemCount - 1)
        }
    }

    override fun getItemCount(): Int = mOptionList.size

    class OptionPopupItemViewHolder(val binding: LayoutOptionPopupItemBinding) :
        BaseRecyclerViewHolder<String>(binding.root)
}