package ru.dbotthepony.mc.otm.compat.vanilla

import net.minecraft.network.chat.Component
import net.minecraft.world.entity.player.Inventory
import ru.dbotthepony.mc.otm.client.render.RenderGravity
import ru.dbotthepony.mc.otm.client.screen.MatteryScreen
import ru.dbotthepony.mc.otm.client.screen.panels.Dock
import ru.dbotthepony.mc.otm.client.screen.panels.FramePanel
import ru.dbotthepony.mc.otm.client.screen.panels.button.DeviceControls
import ru.dbotthepony.mc.otm.client.screen.panels.slot.AbstractSlotPanel
import ru.dbotthepony.mc.otm.client.screen.panels.slot.SlotPanel
import ru.dbotthepony.mc.otm.client.screen.panels.util.GridPanel

class MatteryChestScreen(menu: MatteryChestMenu, inventory: Inventory, title: Component) : MatteryScreen<MatteryChestMenu>(menu, inventory, title) {
	override fun makeMainFrame(): FramePanel<MatteryScreen<*>> {
		val frame = FramePanel.padded(this, AbstractSlotPanel.SIZE * menu.columns.coerceAtLeast(9), AbstractSlotPanel.SIZE * menu.rows + 4f, title)

		frame.makeCloseButton()
		frame.onClose { onClose() }

		val grid = GridPanel.slots(this, frame, menu.columns, menu.rows)
		grid.dock = Dock.FILL
		grid.gravity = RenderGravity.BOTTOM_CENTER

		for (slot in menu.chestSlots)
			SlotPanel(this, grid, slot)

		val controls = DeviceControls(this, frame)
		controls.sortingButtons(menu.sort)

		return frame
	}
}
