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

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.Language
import app.furmeet.events.system.helper.inflate
import app.furmeet.events.system.helper.layoutInflater

class LanguageSelectorListAdapter(private val languages: List<Language>) : ListAdapter {
    override fun isEmpty(): Boolean = languages.isEmpty()
    override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
        val view = convertView
                ?: parent.context.layoutInflater.inflate(R.layout.dialogview_languageselector_item)
        val item = getItem(position)
        view.findViewById<ImageView>(R.id.lang_icon).setImageResource(item.drawableId)
        view.findViewById<TextView>(R.id.lang_label).text = item.nativeName
        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 = languages.size
    override fun getItem(position: Int): Language = languages[position]
}
