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

import net.minecraft.server.level.ServerPlayer
import net.minecraft.world.entity.player.Inventory
import ru.dbotthepony.mc.otm.block.entity.tech.PoweredFurnaceBlockEntity
import ru.dbotthepony.mc.otm.core.immutableList
import ru.dbotthepony.mc.otm.menu.MachineOutputSlot
import ru.dbotthepony.mc.otm.menu.MatteryPoweredMenu
import ru.dbotthepony.mc.otm.menu.MatterySlot
import ru.dbotthepony.mc.otm.menu.input.BooleanInputWithFeedback
import ru.dbotthepony.mc.otm.menu.input.EnergyConfigPlayerInput
import ru.dbotthepony.mc.otm.menu.input.ItemConfigPlayerInput
import ru.dbotthepony.mc.otm.menu.makeSlots
import ru.dbotthepony.mc.otm.menu.widget.ProfiledLevelGaugeWidget
import ru.dbotthepony.mc.otm.menu.widget.ProgressGaugeWidget
import ru.dbotthepony.mc.otm.registry.MMenus

class PoweredFurnaceMenu(
	containerID: Int,
	inventory: Inventory,
	tile: PoweredFurnaceBlockEntity? = null
) : MatteryPoweredMenu(MMenus.POWERED_FURNACE, containerID, inventory, tile) {
	val inputSlots = makeSlots(tile?.inputs, 2, ::MatterySlot)
	val outputSlots = makeSlots(tile?.outputs, 2) { c, s -> MachineOutputSlot(c, s) { tile?.popExperience(ply as ServerPlayer) } }

	val progressGauge = immutableList(2) { ProgressGaugeWidget(this, tile?.jobEventLoops?.get(it)) }
	val itemConfig = ItemConfigPlayerInput(this, tile?.itemConfig, allowPush = true)
	val energyConfig = EnergyConfigPlayerInput(this, tile?.energyConfig, allowPull = true)
	val profiledEnergy = ProfiledLevelGaugeWidget(this, tile?.energy, energyWidget)

	val balanceInputs = BooleanInputWithFeedback(this)

	val upgrades = makeUpgradeSlots(2, tile?.upgrades)

	init {
		if (tile != null) balanceInputs.with(tile::balanceInputs)
		addStorageSlot(inputSlots)
		addStorageSlot(outputSlots)
		addInventorySlots()
	}
}
