package net.pokeranalytics.android.ui.activity

import android.content.Context
import android.content.Intent
import android.os.Bundle
import com.github.mikephil.charting.data.BarDataSet
import com.github.mikephil.charting.data.LineDataSet
import kotlinx.android.synthetic.main.activity_graph.*
import net.pokeranalytics.android.R
import net.pokeranalytics.android.ui.activity.components.PokerAnalyticsActivity
import net.pokeranalytics.android.ui.fragment.GraphFragment


class GraphActivity : PokerAnalyticsActivity() {

	companion object {

		private var lineDataSets: List<LineDataSet>? = null
		private var barDataSets: List<BarDataSet>? = null
		private var style: GraphFragment.Style? = GraphFragment.Style.LINE
		private var activityTitle: String? = null

		/**
		 * Default constructor
		 */
		fun newInstance(
			context: Context, lineDataSets: List<LineDataSet>? = null, barDataSets: List<BarDataSet>? = null,
			style: GraphFragment.Style = GraphFragment.Style.LINE, title: String? = null
		) {
			this.lineDataSets = lineDataSets
			this.barDataSets = barDataSets
			this.style = style
			this.activityTitle = title
			val intent = Intent(context, GraphActivity::class.java)
			context.startActivity(intent)
		}

	}

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

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

		activityTitle?.let {
			setSupportActionBar(toolbar)
			supportActionBar?.setDisplayHomeAsUpEnabled(true)
			title = activityTitle
			activityTitle = null
		}

		style?.let {
			val fragmentTransaction = supportFragmentManager.beginTransaction()
			val graphFragment = GraphFragment.newInstance(lineDataSets, barDataSets, it)
			fragmentTransaction.add(R.id.container, graphFragment)
			fragmentTransaction.commit()
		}

		lineDataSets = null
		barDataSets = null
		style = null
	}

}
