package com.abbidot.tracker.adapter

import android.content.Context
import android.view.View
import com.abbidot.baselibrary.list.BaseRecyclerAdapter
import com.abbidot.baselibrary.list.RecyclerViewHolder
import com.abbidot.baselibrary.util.AppUtils
import com.abbidot.tracker.R
import com.abbidot.tracker.bean.LabelBean
import com.qmuiteam.qmui.layout.QMUILinearLayout
import kotlin.random.Random

/**
 *Created  by .yzq on 2024/2/21/021.
 * @link
 * @description:
 */
class PetLabelsAdapter(ctx: Context, list: MutableList<LabelBean>?) :
    BaseRecyclerAdapter<LabelBean>(ctx, list) {

    private val mLabelBgColorList = mutableListOf(
        R.color.green_color10,
        R.color.label_color2,
        R.color.label_color3,
        R.color.label_color4,
        R.color.label_color5,
        R.color.label_color6,
        R.color.label_color7,
        R.color.label_color8,
        R.color.label_color9,
        R.color.label_color10,
        R.color.label_color11,
        R.color.label_color12,
        R.color.label_color13,
        R.color.label_color14
    )

    override fun getEmptyLayoutId(viewType: Int) = 0

    override fun getItemLayoutId(viewType: Int) = R.layout.item_pet_label_layout_v2

    override fun bindData(holder: RecyclerViewHolder?, position: Int, item: LabelBean) {
        val textView = holder!!.getTextView(R.id.tv_label_v2_name)
        val rootView = holder.itemView as QMUILinearLayout
        val imageView = holder.getImageView(R.id.iv_label_v2_is_select)
        if (item.check) {
            imageView.visibility = View.VISIBLE
        } else {
            imageView.visibility = View.GONE
        }
        textView.text = item.name

        rootView.setBackgroundResource(mLabelBgColorList[Random.nextInt(mLabelBgColorList.size)])

        rootView.radius = AppUtils.dpToPx(6)
    }
}