package net.pokeranalytics.android.ui.view

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.FrameLayout
import androidx.constraintlayout.widget.ConstraintLayout
import kotlinx.android.synthetic.main.row_session_view.view.*
import net.pokeranalytics.android.R
import net.pokeranalytics.android.model.realm.Session
import net.pokeranalytics.android.util.getDayNumber
import net.pokeranalytics.android.util.getShortDayName


class SessionRowView : FrameLayout {

	private lateinit var rowHistorySession: ConstraintLayout

	/**
	 * Constructors
	 */
	constructor(context: Context) : super(context) {
		init()
	}

	constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {
		init()
	}

	constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
		init()
	}

	/**
	 * Init
	 *
	 * @param attrs
	 */
	private fun init() {
		val layoutInflater = LayoutInflater.from(context)
		rowHistorySession = layoutInflater.inflate(R.layout.row_session_view, this, false) as ConstraintLayout
		val layoutParams = FrameLayout.LayoutParams(
			FrameLayout.LayoutParams.MATCH_PARENT,
			FrameLayout.LayoutParams.WRAP_CONTENT
		)

		addView(rowHistorySession, layoutParams)
	}

	/**
	 * Set the session data to the view
	 */
	fun setData(session: Session) {

		rowHistorySession.dateDay.text = session.creationDate.getShortDayName()
		rowHistorySession.dateNumber.text = session.creationDate.getDayNumber()

		// TODO

		var gameTitle = session.getGameTitle()
		if (gameTitle.isEmpty()) {
			gameTitle = "Game title here"
		}

		rowHistorySession.gameType.text = gameTitle

		rowHistorySession.gameInfo.text = "Game info: duration, table size, ..."
		rowHistorySession.gameResult.text = "$ 0"

	}

}