package ru.dbotthepony.mc.otm.client.screen.storage

import net.minecraft.network.chat.Component
import ru.dbotthepony.mc.otm.menu.storage.DriveRackMenu
import net.minecraft.world.entity.player.Inventory
import ru.dbotthepony.mc.otm.capability.FlowDirection
import ru.dbotthepony.mc.otm.client.render.Widgets18
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.DockProperty
import ru.dbotthepony.mc.otm.client.screen.panels.slot.BatterySlotPanel
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.input.IntInputPanel
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
import ru.dbotthepony.mc.otm.client.screen.widget.WidePowerGaugePanel
import ru.dbotthepony.mc.otm.core.TranslatableComponent

class DriveRackScreen(menu: DriveRackMenu, inventory: Inventory, title: Component) :
	MatteryScreen<DriveRackMenu>(menu, inventory, title) {

	override fun makeMainFrame(): FramePanel<MatteryScreen<*>> {
		val frame = super.makeMainFrame()!!

		makeBars(frame, profiledEnergy = menu.profiledEnergy, batterySlot = menu.batterySlot)

		val grid = GridPanel.slots(this, frame, 2, 2)
		grid.dock = Dock.FILL

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

		IntInputPanel(this, frame, menu.insertPriority).also {
			it.dock = Dock.BOTTOM
			it.tooltips.add(TranslatableComponent("otm.gui.insert_priority"))
			it.childrenOrder = -1
			it.dockMargin = DockProperty(left = 20f, right = 10f, bottom = 2f)
		}

		IntInputPanel(this, frame, menu.extractPriority).also {
			it.dock = Dock.BOTTOM
			it.tooltips.add(TranslatableComponent("otm.gui.extract_priority"))
			it.childrenOrder = -2
			it.dockMargin = DockProperty(left = 20f, right = 10f, bottom = 2f)
		}

		val controls = DeviceControls(this, frame, energyConfig = menu.energyConfig, redstoneConfig = menu.redstoneConfig)
		controls.addStorageMode(menu.mode)

		return frame
	}
}
