package ru.dbotthepony.mc.otm.menu.input

import ru.dbotthepony.kommons.util.Delegate
import ru.dbotthepony.mc.otm.core.math.Decimal
import ru.dbotthepony.mc.otm.data.codec.DecimalCodec
import ru.dbotthepony.mc.otm.menu.MatteryMenu
import java.util.function.Supplier
import kotlin.reflect.KMutableProperty0

class DecimalInputWithFeedback(menu: MatteryMenu, allowSpectators: Boolean = false) : AbstractPlayerInputWithFeedback<Decimal>() {
	override val input = menu.decimalInput(allowSpectators) { consumer?.invoke(it) }
	override val field = menu.mSynchronizer.computed(Supplier { supplier?.invoke() ?: Decimal.ZERO }, DecimalCodec.NETWORK)

	constructor(menu: MatteryMenu, allowSpectators: Boolean, state: KMutableProperty0<Decimal>?) : this(menu, allowSpectators) {
		if (state != null)
			with(state)
	}

	constructor(menu: MatteryMenu, allowSpectators: Boolean, state: Delegate<Decimal>?) : this(menu, allowSpectators) {
		if (state != null)
			with(state)
	}

	constructor(menu: MatteryMenu, state: KMutableProperty0<Decimal>?) : this(menu) {
		if (state != null)
			with(state)
	}

	constructor(menu: MatteryMenu, state: Delegate<Decimal>?) : this(menu) {
		if (state != null)
			with(state)
	}
}
