package net.pokeranalytics.android.ui.view

import android.content.Context
import android.graphics.drawable.GradientDrawable
import kotlinx.android.synthetic.main.layout_legend_color.view.*
import kotlinx.android.synthetic.main.layout_legend_default.view.stat1Name
import kotlinx.android.synthetic.main.layout_legend_default.view.stat1Value
import kotlinx.android.synthetic.main.layout_legend_default.view.stat2Name
import kotlinx.android.synthetic.main.layout_legend_default.view.stat2Value
import net.pokeranalytics.android.R
import net.pokeranalytics.android.calculus.Stat
import net.pokeranalytics.android.util.TextFormat
import net.pokeranalytics.android.ui.extensions.setTextFormat
import net.pokeranalytics.android.ui.fragment.GraphFragment

data class MultilineLegendValues(
	var firstTitle: String,
	var secondTitle: String,
	var leftFormat: TextFormat,
	var rightFormat: TextFormat
) : LegendContent

class MultiLineLegendView(context: Context) : LegendView(context = context) {

	override fun getResourceLayout(): Int {
		return R.layout.layout_legend_color
	}

	override fun prepareWithStat(stat: Stat, counter: Int?, style: GraphFragment.Style) {
	}

	override fun setItemData(content: LegendContent, color: Int?) {

		if (content is MultilineLegendValues) {

			this.stat1Name.text = content.firstTitle
			this.stat2Name.text = content.secondTitle

			this.stat1Value.setTextFormat(content.leftFormat, context)
			this.stat2Value.setTextFormat(content.rightFormat, context)

			color?.let {
				val drawable = this.coloredCircle.background
				when (drawable) {
					is GradientDrawable -> {
						drawable.setColor(it)
					} else -> {}
				}
			}

		}

	}

}