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

import net.minecraft.server.level.ServerPlayer
import net.minecraft.world.SimpleContainer
import net.minecraft.world.entity.player.Inventory
import ru.dbotthepony.mc.otm.block.entity.tech.PlatePressBlockEntity
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 TwinPlatePressMenu @JvmOverloads constructor(
	containerID: Int,
	inventory: Inventory,
	tile: PlatePressBlockEntity? = null
) : MatteryPoweredMenu(MMenus.TWIN_PLATE_PRESS, containerID, inventory, tile) {
	val inputSlots = makeSlots(tile?.inputContainer ?: SimpleContainer(2), ::MatterySlot)
	val outputSlots = makeSlots(tile?.outputContainer ?: SimpleContainer(2)) { a, b -> MachineOutputSlot(a, b) { tile?.popExperience(ply as ServerPlayer) } }

	val progressGauge0 = ProgressGaugeWidget(this, tile?.jobEventLoops?.get(0))
	val progressGauge1 = ProgressGaugeWidget(this, tile?.jobEventLoops?.get(1))
	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(4, tile?.upgrades)

	init {
		if (tile != null) {
			balanceInputs.with(tile::balanceInputs)
		}
	}

	init {
		addStorageSlot(inputSlots)
		addStorageSlot(outputSlots)
		addInventorySlots()
	}
}
