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.Report
import net.pokeranalytics.android.ui.activity.components.PokerAnalyticsActivity
import net.pokeranalytics.android.ui.fragment.ReportDetailsFragment



class ReportDetailsActivity : PokerAnalyticsActivity() {

	companion object {

		// Unparcel fails when setting a custom Parcelable object on Entry so we use a static reference to passe objects
		private var report: Report? = null
		private var reportTitle: String = ""

		/**
		 * Default constructor
		 */
		fun newInstance(context: Context, report: Report, reportTitle: String) {
			//parameters = GraphParameters(stat, group, report)
			this.report = report
			this.reportTitle = reportTitle
			val intent = Intent(context, ReportDetailsActivity::class.java)
			context.startActivity(intent)
		}

	}

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

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

		report?.let {
			val fragmentTransaction = supportFragmentManager.beginTransaction()
			val reportDetailsFragment = ReportDetailsFragment.newInstance(it, reportTitle)
			fragmentTransaction.add(R.id.reportDetailsContainer, reportDetailsFragment)
			fragmentTransaction.commit()

			report = null
		}
	}

}
