package ru.dbotthepony.mc.otm.menu.matter

import net.minecraft.world.SimpleContainer
import net.minecraft.world.entity.player.Inventory
import ru.dbotthepony.mc.otm.core.immutableList
import ru.dbotthepony.mc.otm.block.entity.matter.MatterCapacitorBankBlockEntity
import ru.dbotthepony.mc.otm.core.math.Decimal
import ru.dbotthepony.mc.otm.menu.MatterContainerInputSlot
import ru.dbotthepony.mc.otm.menu.MatteryMenu
import ru.dbotthepony.mc.otm.menu.input.ItemConfigPlayerInput
import ru.dbotthepony.mc.otm.menu.widget.LevelGaugeWidget
import ru.dbotthepony.mc.otm.registry.MMenus

class MatterCapacitorBankMenu @JvmOverloads constructor(
	p_38852_: Int,
	inventory: Inventory,
	tile: MatterCapacitorBankBlockEntity? = null
) : MatteryMenu(MMenus.MATTER_CAPACITOR_BANK, p_38852_, inventory, tile) {
	val matterGauge = LevelGaugeWidget(this)
	val totalMatterGauge = LevelGaugeWidget(this)
	val itemConfig = ItemConfigPlayerInput(this, tile?.itemConfig)

	val storageSlots: List<MatterContainerInputSlot>

	init {
		if (tile != null) {
			matterGauge.with(tile)
			totalMatterGauge.with({
				tile.matterNode.graph.getMatterStorageLevel()
			}, {
				tile.matterNode.graph.getMatterStorageMaxLevel()
			})
		}

		val container = tile?.container ?: SimpleContainer(2 * 6)

		storageSlots = immutableList(2 * 6) {
			addStorageSlot(MatterContainerInputSlot(container, it))
		}

		addInventorySlots()
	}
}
