package app.furmeet.events.system.schedule.adapters

import android.content.res.ColorStateList
import android.database.DataSetObserver
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.ListAdapter
import android.widget.TextView
import app.furmeet.events.bff.R
import app.furmeet.events.system.helper.inflate
import app.furmeet.events.system.helper.layoutInflater
import app.furmeet.events.bff.databinding.ActivitySearchFilterCriteriaItemdialogBinding

class TagTripleListAdapter(val tagTriples: List<Triple<String, Int, () -> Any>>) : ListAdapter {
    override fun isEmpty(): Boolean = tagTriples.isEmpty()
    override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
        val view = convertView
                ?: parent.context.layoutInflater.inflate(R.layout.activity_search_filter_criteria_itemdialog)
        val item = tagTriples[position]
        view.findViewById<TextView>(R.id.tag_label).text = item.first
        view.findViewById<ImageView>(R.id.tag_color).imageTintList = ColorStateList.valueOf(item.second)
        return view
    }

    override fun registerDataSetObserver(observer: DataSetObserver?) {}
    override fun getItemViewType(position: Int): Int = 0
    override fun getViewTypeCount(): Int = 1
    override fun isEnabled(position: Int): Boolean = true
    override fun getItemId(position: Int): Long = position.toLong()
    override fun hasStableIds(): Boolean = true
    override fun areAllItemsEnabled(): Boolean = true
    override fun unregisterDataSetObserver(observer: DataSetObserver?) {}
    override fun getCount(): Int = tagTriples.size
    override fun getItem(position: Int): Any = tagTriples[position]
}