package ru.dbotthepony.mc.otm.menu.tech

import net.minecraft.world.SimpleContainer
import net.minecraft.world.entity.player.Inventory
import ru.dbotthepony.mc.otm.block.entity.RedstoneSetting
import ru.dbotthepony.mc.otm.block.entity.tech.CobblerBlockEntity
import ru.dbotthepony.mc.otm.core.immutableList
import ru.dbotthepony.mc.otm.menu.MachineOutputSlot
import ru.dbotthepony.mc.otm.menu.MatteryMenu
import ru.dbotthepony.mc.otm.menu.input.EnumInputWithFeedback
import ru.dbotthepony.mc.otm.menu.input.ItemConfigPlayerInput
import ru.dbotthepony.mc.otm.menu.widget.ProgressGaugeWidget
import ru.dbotthepony.mc.otm.registry.MMenus

class CobblerMenu @JvmOverloads constructor(
	p_38852_: Int,
	inventory: Inventory,
	tile: CobblerBlockEntity? = null
) : MatteryMenu(MMenus.COBBLESTONE_GENERATOR, p_38852_, inventory, tile) {
	val storageSlots = (tile?.container ?: SimpleContainer(CobblerBlockEntity.CONTAINER_SIZE)).let { c -> immutableList(c.containerSize) { addStorageSlot(MachineOutputSlot(c, it)) } }
	val redstone = EnumInputWithFeedback<RedstoneSetting>(this)
	val itemConfig = ItemConfigPlayerInput(this)

	val progress = ProgressGaugeWidget(this)

	init {
		if (tile != null) {
			progress.with(tile.jobEventLoops[0])
			redstone.with(tile.redstoneControl::redstoneSetting)
			itemConfig.with(tile.itemConfig)
		}

		addInventorySlots()
	}
}
