package net.pokeranalytics.android.ui.fragment

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager
import kotlinx.android.synthetic.main.fragment_settings.*
import net.pokeranalytics.android.R
import net.pokeranalytics.android.calculus.Stat
import net.pokeranalytics.android.ui.adapter.components.RowRepresentableAdapter
import net.pokeranalytics.android.ui.adapter.components.RowRepresentableDataSource
import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.fragment.components.PokerAnalyticsFragment

class StatsFragment : PokerAnalyticsFragment(), RowRepresentableDataSource {

    companion object {

        /**
         * Create new instance
         */
        fun newInstance(): StatsFragment {
            val fragment = StatsFragment()
            val bundle = Bundle()
            fragment.arguments = bundle
            return fragment
        }
    }

    private lateinit var statsAdapterRow: RowRepresentableAdapter

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        return inflater.inflate(R.layout.fragment_stats, container, false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        initData()
    }

    override fun adapterRows(): ArrayList<RowRepresentable> {
        val rows = ArrayList<RowRepresentable>()
        rows.addAll(Stat.values())
        return rows
    }

    /**
     * Init data
     */
    private fun initData() {

        val viewManager = LinearLayoutManager(requireContext())
        this.statsAdapterRow = RowRepresentableAdapter(
            this
        )

        recyclerView.apply {
            setHasFixedSize(true)
            layoutManager = viewManager
            adapter = statsAdapterRow
        }
    }
}