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

import net.minecraft.network.chat.Component
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.core.TranslatableComponent
import ru.dbotthepony.mc.otm.client.screen.panels.*
import ru.dbotthepony.mc.otm.client.screen.panels.button.CheckBoxLabelInputPanel
import ru.dbotthepony.mc.otm.client.screen.panels.button.DeviceControls
import ru.dbotthepony.mc.otm.client.screen.panels.button.LargeEnumRectangleButtonPanel
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.FilterSlotPanel
import ru.dbotthepony.mc.otm.client.screen.panels.util.GridPanel

import ru.dbotthepony.mc.otm.menu.storage.StorageBusMenu

class StorageBusScreen(menu: StorageBusMenu, inventory: Inventory, title: Component) :
	MatteryScreen<StorageBusMenu>(menu, inventory, title) {
	override fun makeMainFrame(): FramePanel<MatteryScreen<*>> {
		val frame = FramePanel(this, 150f, 126f, title)

		makeBars(frame, profiledEnergy = menu.profiledEnergy, batterySlot = menu.batterySlot)
		val right = EditablePanel(this, frame, width = AbstractSlotPanel.SIZE * 6f)
		right.dock = Dock.RIGHT
		val grid = GridPanel(this, right, columns = 6, rows = 3, height = AbstractSlotPanel.SIZE * 3f)
		grid.dock = Dock.TOP
		grid.dockBottom = 2f

		for (slot in menu.busFilterSlots)
			FilterSlotPanel(this, grid, slot)

		IntInputPanel(this, right, menu.insertPriority).also {
			it.dock = Dock.BOTTOM
			it.dockBottom = 2f
			it.tooltips.add(TranslatableComponent("otm.gui.insert_priority"))
			it.childrenOrder = -1
		}

		IntInputPanel(this, right, menu.extractPriority).also {
			it.dock = Dock.BOTTOM
			it.dockBottom = 2f
			it.tooltips.add(TranslatableComponent("otm.gui.extract_priority"))
			it.childrenOrder = -2
		}

		CheckBoxLabelInputPanel(this, right, menu.busFilterState, TranslatableComponent("otm.gui.filter.is_whitelist")).also {
			it.dock = Dock.BOTTOM
			it.childrenOrder = -3
		}

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

		return frame
	}
}
