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

import net.minecraft.world.Container
import kotlin.jvm.JvmOverloads
import net.minecraft.world.entity.player.Inventory
import ru.dbotthepony.mc.otm.block.entity.tech.BatteryBankBlockEntity
import net.minecraft.world.SimpleContainer
import ru.dbotthepony.mc.otm.block.entity.RedstoneSetting
import ru.dbotthepony.mc.otm.core.immutableList
import ru.dbotthepony.mc.otm.menu.BatterySlot
import ru.dbotthepony.mc.otm.menu.MatteryMenu
import ru.dbotthepony.mc.otm.menu.MatterySlot
import ru.dbotthepony.mc.otm.menu.input.EnergyConfigPlayerInput
import ru.dbotthepony.mc.otm.menu.input.EnumInputWithFeedback
import ru.dbotthepony.mc.otm.menu.input.ItemConfigPlayerInput
import ru.dbotthepony.mc.otm.menu.widget.ProfiledLevelGaugeWidget
import ru.dbotthepony.mc.otm.registry.MMenus

class BatteryBankMenu @JvmOverloads constructor(
	p_38852_: Int,
	inventory: Inventory,
	tile: BatteryBankBlockEntity? = null,
) : MatteryMenu(MMenus.BATTERY_BANK, p_38852_, inventory, tile) {
	val powerLevel = ProfiledLevelGaugeWidget(this, tile?.energyConfig?.energy)
	val storageSlots: List<MatterySlot>
	val redstone = EnumInputWithFeedback(this, RedstoneSetting::class.java)
	val energyConfig = EnergyConfigPlayerInput(this, allowPull = false, allowPush = true)
	val itemConfig = ItemConfigPlayerInput(this, allowPull = false, allowPush = false)

	init {
		if (tile != null) {
			redstone.with(tile.redstoneControl::redstoneSetting)
			energyConfig.with(tile.energyConfig)
			itemConfig.with(tile.itemConfig)
		}

		val container: Container = tile?.container ?: SimpleContainer(BatteryBankBlockEntity.CAPACITY)

		storageSlots = immutableList(BatteryBankBlockEntity.CAPACITY) {
			addStorageSlot(BatterySlot(container, it))
		}

		addInventorySlots()
	}
}
