package ru.dbotthepony.mc.otm.menu.decorative

import net.minecraft.world.entity.player.Inventory
import net.minecraft.world.inventory.Slot
import ru.dbotthepony.mc.otm.block.entity.RedstoneSetting
import ru.dbotthepony.mc.otm.block.entity.decorative.HoloSignBlockEntity
import ru.dbotthepony.mc.otm.menu.MatteryMenu
import ru.dbotthepony.mc.otm.menu.input.BooleanInputWithFeedback
import ru.dbotthepony.mc.otm.menu.input.EnumInputWithFeedback
import ru.dbotthepony.mc.otm.menu.input.StringInputWithFeedback
import ru.dbotthepony.mc.otm.registry.MMenus

class HoloSignMenu @JvmOverloads constructor(
	containerId: Int,
	inventory: Inventory,
	tile: HoloSignBlockEntity? = null
) : MatteryMenu(MMenus.HOLO_SIGN, containerId, inventory, tile) {
	val text = StringInputWithFeedback(this)
	val locked = BooleanInputWithFeedback(this)
	val redstone = EnumInputWithFeedback(this, RedstoneSetting::class.java)

	init {
		text.filter { it.isCreative || !locked.value }
		redstone.filter { it.isCreative || !locked.value }
		locked.filter { it.isCreative }

		if (tile != null) {
			text.withConsumer { if (tile.isLocked) tile.signText = it else tile.signText = HoloSignBlockEntity.truncate(it) }.withSupplier(tile::signText)
			locked.with(tile::isLocked)
			redstone.with(tile.redstoneControl::redstoneSetting)
		}
	}
}
