package com.aegir.demo.fragments

import android.os.Bundle
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.aegir.demo.R
import com.aegir.vmms.vmd.model.MapUnit

/**
 * A fragment representing a list of Items.
 */
class FloorMapUnitsInfoFragment constructor(
    private val mapUnits: List<MapUnit>? = null
) : Fragment() {

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        val view = inflater.inflate(R.layout.fragment_floor_map_units_info_list, container, false)

        if (view is RecyclerView) {
            with(view) {
                layoutManager = LinearLayoutManager(context)
                adapter = MapUnitInfoRecyclerViewAdapter(mapUnits)
            }
        }
        return view
    }

    companion object {

        private const val ARG_MAP_UNITS = "map-units"

        @JvmStatic
        fun newInstance(mapUnits: ArrayList<MapUnit>) =
            FloorMapUnitsInfoFragment(mapUnits).apply {
                arguments = Bundle().apply {
                    putSerializable(ARG_MAP_UNITS, mapUnits)
                }
            }
    }
}