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

import net.minecraft.client.gui.GuiGraphics
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.slot.AbstractSlotPanel
import ru.dbotthepony.mc.otm.client.screen.panels.slot.BatterySlotPanel
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.EditablePanel
import ru.dbotthepony.mc.otm.client.screen.panels.FramePanel
import ru.dbotthepony.mc.otm.client.screen.panels.PlayerEquipmentPanel
import ru.dbotthepony.mc.otm.client.screen.panels.button.makeDeviceControls
import ru.dbotthepony.mc.otm.client.screen.panels.makeCuriosPanel
import ru.dbotthepony.mc.otm.client.screen.panels.SpritePanel
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.EnergyServoMenu

class EnergyServoScreen(menu: EnergyServoMenu, inventory: Inventory, title: Component) : MatteryScreen<EnergyServoMenu>(menu, inventory, title) {
	override fun makeMainFrame(): FramePanel<MatteryScreen<*>> {
		val frame = FramePanel.padded(this,
			width = AbstractSlotPanel.SIZE * 2f + HorizontalPowerGaugePanel.GAUGE_BACKGROUND_TALL.width + 8f + ProgressGaugePanel.GAUGE_BACKGROUND.width * 2f,
			AbstractSlotPanel.SIZE + PlayerEquipmentPanel.HEIGHT + 4f, title)

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

		val equipment = PlayerEquipmentPanel(this, frame, armorSlots = menu.equipment.armorSlots)
		equipment.dock = Dock.FILL
		equipment.dockResize = DockResizeMode.NONE

		makeCuriosPanel(this, frame, menu.equipment.curiosSlots, autoAlign = true)

		val strip = EditablePanel(this, frame, height = AbstractSlotPanel.SIZE)
		strip.dock = Dock.BOTTOM

		BatterySlotPanel(this, strip, menu.dischargeSlot).also {
			it.dock = Dock.LEFT
			it.dockRight = 2f
		}

		SpritePanel(this, strip, ProgressGaugePanel.GAUGE_BACKGROUND).also {
			it.dock = Dock.LEFT
			it.dockRight = 2f
			it.dockTop = 2f
		}

		TallHorizontalProfiledPowerGaugePanel(this, strip, menu.powerGauge).also {
			it.dock = Dock.LEFT
			it.dockRight = 2f
		}

		object : EditablePanel<EnergyServoScreen>(this@EnergyServoScreen, strip) {
			init {
				dock = Dock.LEFT
				dockRight = 2f
				dockTop = 2f
				width = ProgressGaugePanel.GAUGE_BACKGROUND.width
			}

			override fun innerRender(graphics: GuiGraphics, mouseX: Float, mouseY: Float, partialTick: Float) {
				ProgressGaugePanel.GAUGE_BACKGROUND.render(graphics)
			}
		}

		BatterySlotPanel(this, strip, menu.chargeSlot).also {
			it.dock = Dock.LEFT
			it.dockRight
		}

		makeDeviceControls(this, frame, redstoneConfig = menu.redstoneConfig, itemConfig = menu.itemConfig, energyConfig = menu.energyConfig)

		return frame
	}
}
