package net.pokeranalytics.android.ui.activity

import android.content.Context
import android.content.Intent
import android.os.Bundle
import net.pokeranalytics.android.R
import net.pokeranalytics.android.calculus.ComputableGroup
import net.pokeranalytics.android.calculus.Report
import net.pokeranalytics.android.calculus.Stat
import net.pokeranalytics.android.ui.activity.components.PokerAnalyticsActivity
import net.pokeranalytics.android.ui.fragment.StatisticDetailsFragment


class StatisticsDetailsParameters(var stat: Stat, var computableGroup: ComputableGroup, var report: Report, var title: String? = null)

class StatisticDetailsActivity : PokerAnalyticsActivity() {

	companion object {

		// Unparcel fails when setting a custom Parcelable object on Entry so we use a static reference to passe objects
		private var parameters: StatisticsDetailsParameters? = null
		private var displayAggregationChoices: Boolean = true

		/**
		 * Default constructor
		 */
		fun newInstance(context: Context, stat: Stat, group: ComputableGroup, report: Report, displayAggregationChoices: Boolean = true, title: String? = null) {
			parameters = StatisticsDetailsParameters(stat, group, report, title)
			this.displayAggregationChoices = displayAggregationChoices
			val intent = Intent(context, StatisticDetailsActivity::class.java)
			context.startActivity(intent)
		}

	}

	override fun onCreate(savedInstanceState: Bundle?) {
		super.onCreate(savedInstanceState)
		setContentView(R.layout.activity_statistic_details)
		initUI()
	}

	/**
	 * Init UI
	 */
	private fun initUI() {

		val fragmentTransaction = supportFragmentManager.beginTransaction()
		val statisticDetailsFragment = StatisticDetailsFragment()
		fragmentTransaction.add(R.id.statisticDetailsContainer, statisticDetailsFragment)
		fragmentTransaction.commit()

		parameters?.let {
			statisticDetailsFragment.setData(it.stat, it.computableGroup, it.report, displayAggregationChoices, it.title)
			parameters = null
		}

	}

}
