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.PatternStorageBlockEntity
import ru.dbotthepony.mc.otm.core.math.Decimal
import ru.dbotthepony.mc.otm.menu.MatteryMenu
import ru.dbotthepony.mc.otm.menu.PatternSlot
import ru.dbotthepony.mc.otm.menu.input.ItemConfigPlayerInput
import ru.dbotthepony.mc.otm.menu.widget.LevelGaugeWidget
import ru.dbotthepony.mc.otm.registry.MMenus

class PatternStorageMenu @JvmOverloads constructor(
	p_38852_: Int,
	inventory: Inventory,
	tile: PatternStorageBlockEntity? = null
) : MatteryMenu(MMenus.PATTERN_STORAGE, p_38852_, inventory, tile) {
	val storedThis = LevelGaugeWidget(this, tile)
	val storedGrid = LevelGaugeWidget(this)
	val itemConfig = ItemConfigPlayerInput(this, tile?.itemConfig)

	val storageSlots: List<PatternSlot>

	init {
		if (tile != null) {
			storedGrid.with({
				Decimal(tile.matterNode.graph.patternCount)
			}, {
				Decimal(tile.matterNode.graph.patternCapacity)
			})
		}

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

		storageSlots = immutableList(2 * 4) {
			addStorageSlot(PatternSlot(patterns, it))
		}

		addInventorySlots()
	}
}
