package com.led.scroller.barrage.banner.ui.adapter

import android.annotation.SuppressLint
import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.core.provider.FontsContractCompat
import androidx.recyclerview.widget.RecyclerView
import com.led.scroller.barrage.banner.R
import com.led.scroller.barrage.banner.bean.FontColorBean
import com.led.scroller.barrage.banner.bean.FontSizeBean
import com.led.scroller.barrage.banner.databinding.AdapterColorItemBinding
import com.led.scroller.barrage.banner.databinding.AdapterFontItemBinding

class FontSizeAdapter(
    private val context: Context,
    private val fontSizeList: MutableList<FontSizeBean>,
) :
    RecyclerView.Adapter<FontSizeAdapter.FontSizeViewHolder>() {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): FontSizeViewHolder {
        val inflater = LayoutInflater.from(context)
        val binding = AdapterFontItemBinding.inflate(inflater, parent, false)
        return FontSizeViewHolder(binding)
    }

    @SuppressLint("UseCompatLoadingForDrawables")
    override fun onBindViewHolder(holder: FontSizeViewHolder, position: Int) {
        val bean = fontSizeList[position]
        holder.binding.textView.text = bean.name
        if (bean.select) {
            holder.binding.selectView.background =
                context.getDrawable(R.drawable.drw_round_stroke_selected)
        } else {
            holder.binding.selectView.background =
                context.getDrawable(R.drawable.drw_round_stroke_unselected)
        }
        holder.itemView.setOnClickListener {
            if (itemClickListener != null) {
                itemClickListener?.onItemClick(position)
            }
        }
    }

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

    inner class FontSizeViewHolder(val binding: AdapterFontItemBinding) :
        RecyclerView.ViewHolder(binding.root)

    private var itemClickListener: OnItemClickListener? = null

    fun setOnItemClickListener(listener: OnItemClickListener) {
        itemClickListener = listener
    }

    interface OnItemClickListener {
        fun onItemClick(position: Int)
    }
}