package importantedto.deserveedto.manufactureredto.viableedto

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.WomanedtoBinding
import importantedto.concreteedto.cameedto.Ridgeedto
import importantedto.maidedto.witnessedto.nationalismedto.Gestureedto.inflate

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

    private val beanList = arrayListOf<Ridgeedto>()

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

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

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

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

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

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