package net.pokeranalytics.android.ui.fragment.report

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import net.pokeranalytics.android.R
import net.pokeranalytics.android.calculus.Report

class TableReportFragment : AbstractReportFragment() {

	private lateinit var tableReportFragment: ComposableTableReportFragment

	companion object {

		fun newInstance(report: Report, title: String): TableReportFragment {
			val fragment = TableReportFragment()
			fragment.reportTitle = title
			fragment.setReport(report)
			val bundle = Bundle()
			fragment.arguments = bundle
			return fragment
		}
	}

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

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

	private fun initUI() {

		setDisplayHomeAsUpEnabled(true)
		setToolbarTitle(reportTitle)

		val fragmentTransaction = parentActivity?.supportFragmentManager?.beginTransaction()
		val fragment = ComposableTableReportFragment.newInstance(this.selectedReport)
		fragmentTransaction?.add(R.id.tableReportContainer, fragment)
		fragmentTransaction?.commit()

		this.tableReportFragment = fragment

	}

}