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

import net.minecraft.network.chat.Component
import net.minecraft.world.entity.player.Inventory
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.DockResizeMode
import ru.dbotthepony.mc.otm.client.screen.panels.FramePanel
import ru.dbotthepony.mc.otm.client.screen.panels.SpritePanel
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.BatterySlotPanel
import ru.dbotthepony.mc.otm.client.screen.widget.HorizontalPowerGaugePanel
import ru.dbotthepony.mc.otm.client.screen.widget.ProgressGaugePanel
import ru.dbotthepony.mc.otm.client.screen.widget.TallHorizontalProfiledPowerGaugePanel
import ru.dbotthepony.mc.otm.menu.tech.EnergyHatchMenu

class EnergyHatchScreen(menu: EnergyHatchMenu, inventory: Inventory, title: Component) : MatteryScreen<EnergyHatchMenu>(menu, inventory, title) {
	override fun makeMainFrame(): FramePanel<MatteryScreen<*>> {
		val frame = FramePanel.padded(this, null, ProgressGaugePanel.GAUGE_BACKGROUND.width + 10f + HorizontalPowerGaugePanel.GAUGE_BACKGROUND_TALL.width + menu.inputSlots.size * AbstractSlotPanel.SIZE, AbstractSlotPanel.SIZE, getTitle())

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

		val slots = menu.inputSlots.map { slot ->
			val panel = BatterySlotPanel(this, frame, slot)
			panel.dock = Dock.LEFT
			panel.dockResize = DockResizeMode.NONE
			panel
		}

		val gauge = TallHorizontalProfiledPowerGaugePanel(this, frame, menu.gauge)
		gauge.dock = Dock.RIGHT

		val arrow = SpritePanel(this, frame, ProgressGaugePanel.GAUGE_BACKGROUND)
		arrow.dock = Dock.RIGHT
		arrow.dockRight = 5f
		arrow.dockLeft = 5f
		arrow.dockBottom = 1f
		arrow.dockResize = DockResizeMode.NONE

		if (!menu.isInput) {
			slots.forEach { it.dock = Dock.RIGHT }
			arrow.dock = Dock.LEFT
			gauge.dock = Dock.LEFT
		}

		DeviceControls(this, frame, redstoneConfig = menu.redstone)

		return frame
	}
}
