package net.pokeranalytics.android.ui.activity

import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.fragment.app.Fragment
import kotlinx.android.synthetic.main.activity_data_list.*
import net.pokeranalytics.android.R
import net.pokeranalytics.android.ui.activity.components.PokerAnalyticsActivity
import net.pokeranalytics.android.ui.fragment.DataListFragment
import net.pokeranalytics.android.ui.interfaces.FilterActivityRequestCode

class DataListActivity : PokerAnalyticsActivity() {

	enum class IntentKey(val keyName: String) {
		DATA_TYPE("DATA_TYPE"),
		LIVE_DATA_TYPE("LIVE_DATA_TYPE"),
		ITEM_DELETED("ITEM_DELETED"),
		SHOW_ADD_BUTTON("SHOW_ADD_BUTTON"),
	}

	companion object {
		fun newInstance(context: Context, dataType: Int) {
			context.startActivity(getIntent(context, dataType))
		}

		fun newSelectInstance(fragment: Fragment, dataType: Int, showAddButton: Boolean = true) {
			val context = fragment.requireContext()
			fragment.startActivityForResult(getIntent(context, dataType, showAddButton), FilterActivityRequestCode.SELECT_FILTER.ordinal)
		}

		private fun getIntent(context: Context, dataType: Int, showAddButton: Boolean = true): Intent {
			val intent = Intent(context, DataListActivity::class.java)
			intent.putExtra(IntentKey.DATA_TYPE.keyName, dataType)
			intent.putExtra(IntentKey.SHOW_ADD_BUTTON.keyName, showAddButton)
			return intent
		}
	}

	override fun onCreate(savedInstanceState: Bundle?) {
		super.onCreate(savedInstanceState)
		setContentView(R.layout.activity_data_list)

		initUI()
	}

	/**
	 * Init UI
	 */
	private fun initUI() {
		val dataType = intent.getIntExtra(IntentKey.DATA_TYPE.keyName, 0)
		val showAddButton = intent.getBooleanExtra(IntentKey.SHOW_ADD_BUTTON.keyName, true)
		val fragment = dataListFragment as DataListFragment
		fragment.setData(dataType)
		fragment.updateUI(showAddButton)
	}

}