package net.pokeranalytics.android.ui.activity

import android.content.Context
import android.content.Intent
import android.os.Bundle
import kotlinx.android.synthetic.main.activity_editable_data.*
import net.pokeranalytics.android.R
import net.pokeranalytics.android.ui.activity.components.PokerAnalyticsActivity
import net.pokeranalytics.android.ui.fragment.EditableDataFragment

class EditableDataActivity : PokerAnalyticsActivity() {
	enum class IntentKey(val keyName : String) {
		DATATYPE("DATATYPE"),
		PRIMARYKEY("PRIMARYKEY");
	}

	companion object {
		fun newInstance(context: Context, dataType: Int, primaryKey: String? = null) {
			val intent = Intent(context, EditableDataActivity::class.java)
			intent.putExtra(IntentKey.DATATYPE.keyName, dataType)
			primaryKey?.let {
				intent.putExtra(IntentKey.PRIMARYKEY.keyName, it)
			}
			context.startActivity(intent)
		}
	}

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

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

		val dataType = intent.getIntExtra(IntentKey.DATATYPE.keyName, 0)
		val primaryKey = intent.getStringExtra(IntentKey.PRIMARYKEY.keyName)
		val fragment = editableDataFragment as EditableDataFragment
		fragment.setData(dataType, primaryKey)
	}
}