package warpic

import android.annotation.SuppressLint
import android.graphics.Color
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.annotation.Dimension
import androidx.core.view.isVisible
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import com.easy.clean.R
import tooic.fatalityic.corroborateic.poisedic.drowningic.rainic.Schemeic
import com.easy.clean.databinding.BrayicBinding
import androidx.core.graphics.toColorInt

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

    private val beanList = arrayListOf<Schemeic>()

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

    fun Int.inflate(parent: ViewGroup, attachToRoot: Boolean = false): View {
        return LayoutInflater.from(parent.context).inflate(this, parent, attachToRoot)
    }

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

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

    override fun onBindViewHolder(holder: YYDS, position: Int) {
        val binding = BrayicBinding.bind(holder.itemView)
        val bean = beanList[position]
        val context = holder.itemView.context
        binding.beadyic.text = bean.tittle
        binding.ladleic.isVisible = bean.isSelect
        if (bean.isSelect) {
            binding.beadyic.setTextColor(Color.BLACK)
            binding.beadyic.setTextSize(Dimension.SP, 18f)
        } else {
            binding.beadyic.setTextColor("#747474".toColorInt())
            binding.beadyic.setTextSize(Dimension.SP, 16f)
        }
        binding.root.setOnClickListener {
            click.invoke(bean)
        }
    }

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