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.BooleanSupplier
import kotlin.reflect.KMutableProperty0

class BooleanInputWithFeedback(menu: MatteryMenu, allowSpectators: Boolean = false) : AbstractPlayerInputWithFeedback<Boolean>() {
	override val input = menu.booleanInput(allowSpectators) { consumer?.invoke(it) }
	override val field = menu.mSynchronizer.computedBool(BooleanSupplier { supplier?.invoke() ?: false })

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

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

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

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

	fun switchValue() {
		accept(!value)
	}
}
