package com.aegir.demo.fragments

import androidx.recyclerview.widget.RecyclerView
import android.view.LayoutInflater
import android.view.ViewGroup
import android.widget.TextView
import com.aegir.demo.databinding.FragmentFloorMapUnitsInfoBinding

import com.aegir.vmms.vmd.model.MapUnit

/**
 * [RecyclerView.Adapter] that can display a [MapUnit].
 */
class MapUnitInfoRecyclerViewAdapter(
    private val values: List<MapUnit>?
) : RecyclerView.Adapter<MapUnitInfoRecyclerViewAdapter.ViewHolder>() {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {

        return ViewHolder(
            FragmentFloorMapUnitsInfoBinding.inflate(
                LayoutInflater.from(parent.context),
                parent,
                false
            )
        )

    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        values?.let {
            val item = it[position]
            holder.nameTextView.text = item.name
            holder.categoryTextview.text = item.category ?: ""
            holder.idTextview.text = item.id
            holder.floorIdTextview.text = item.floor?.id ?: ""
            holder.placeIdTextview.text = item.placeId ?: ""
        }
    }

    override fun getItemCount(): Int = values?.size ?: 0

    inner class ViewHolder(binding: FragmentFloorMapUnitsInfoBinding) :
        RecyclerView.ViewHolder(binding.root) {
        val nameTextView: TextView = binding.nameValueTextView
        val categoryTextview: TextView = binding.categoryValueTextView
        val idTextview: TextView = binding.idValueTextView
        val floorIdTextview: TextView = binding.floorIdValueTextView
        val placeIdTextview: TextView = binding.placeIdValueTextView

    }

}