package rallyedto.dumpedto.editionedto

import android.annotation.SuppressLint
import android.view.View
import android.view.ViewGroup
import androidx.annotation.Dimension
import androidx.core.content.ContextCompat
import androidx.core.view.isVisible
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import com.base.datarecovery.R
import com.base.datarecovery.databinding.PaymentedtoBinding
import rallyedto.farewelledto.Strategicedto.inflate
import rallyedto.policeedto.huntedto.Drewedto

class Failededto(
    val click: (bean: Drewedto) -> Unit
) : RecyclerView.Adapter<Failededto.YYDS>() {

    private val beanList = arrayListOf<Drewedto>()

    inner class YYDS(view: View) : ViewHolder(view)

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

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

    override fun onBindViewHolder(holder: YYDS, position: Int) {
        val binding = PaymentedtoBinding.bind(holder.itemView)
        val bean = beanList[position]
        val context = holder.itemView.context
        binding.promoteedto.text = bean.tittle
        binding.usefuledto.isVisible = bean.isSelect
        if (bean.isSelect) {
            binding.promoteedto.setTextColor(ContextCompat.getColor(context, R.color.snapedto))
            binding.promoteedto.setTextSize(Dimension.SP, 18f)
        } else {
            binding.promoteedto.setTextColor(ContextCompat.getColor(context, R.color.firmedto))
            binding.promoteedto.setTextSize(Dimension.SP, 16f)
        }
        binding.root.setOnClickListener {
            click.invoke(bean)
        }
    }

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