package importantedto.deserveedto.manufactureredto.viableedto

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

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

    private val beanList = arrayListOf<Plainedto>()

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

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

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

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

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