package rowedto.jockeyedto.sheetedto.meadowedto.naturaledto.idealedto

import android.annotation.SuppressLint
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.base.datarecovery.R
import com.base.datarecovery.databinding.FeetedtoBinding
import rowedto.jockeyedto.sheetedto.balsamedto.formaledto.orientationedto.Ambitionedto.inflate
import rowedto.jockeyedto.sheetedto.debutedto.revolutionaryedto.Toneedto

class Nominationedto(val isUninstall: Boolean = false, val click: (packageName: String) -> Unit) :
    RecyclerView.Adapter<Nominationedto.AAA>() {

    private val beanList = arrayListOf<Toneedto>()

    class AAA(view: View) : RecyclerView.ViewHolder(view)

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): AAA {
        return AAA(R.layout.feetedto.inflate(parent))
    }

    override fun getItemCount(): Int {
        return beanList.size
    }

    @SuppressLint("SetTextI18n")
    override fun onBindViewHolder(holder: AAA, position: Int) {
        val binding = FeetedtoBinding.bind(holder.itemView)
        val bean = beanList[position]
        binding.shiftedto.setImageDrawable(bean.icon)
        binding.glassesedto.text = bean.name
        binding.shineedto.setOnClickListener {
            click.invoke(bean.packageName)
        }
        if (isUninstall) {
            binding.shineedto.text = "UnInstall"
        }
    }

    @SuppressLint("NotifyDataSetChanged")
    fun setData(list: List<Toneedto>) {
        beanList.clear()
        beanList.addAll(list)
        notifyDataSetChanged()
    }

    @SuppressLint("NotifyDataSetChanged")
    fun removeBean(pkg: String) {
        beanList.removeIf { it.packageName == pkg }
        notifyDataSetChanged()
    }
}