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

import ru.dbotthepony.mc.otm.core.GetterSetter
import ru.dbotthepony.mc.otm.menu.MatteryMenu
import java.util.function.IntSupplier
import kotlin.reflect.KMutableProperty0

class IntInputWithFeedback(menu: MatteryMenu, allowSpectators: Boolean = false) : AbstractPlayerInputWithFeedback<Int>() {
	override val input = menu.intInput(allowSpectators) { consumer?.invoke(it) }
	override val field = menu.mSynchronizer.computedInt(IntSupplier { supplier?.invoke() ?: 0 })

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

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

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

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