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

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.EditablePanel
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.SlotPanel
import ru.dbotthepony.mc.otm.client.screen.panels.util.GridPanel
import ru.dbotthepony.mc.otm.client.screen.widget.ProgressGaugePanel
import ru.dbotthepony.mc.otm.compat.jei.MatterEntanglerRecipeCategory
import ru.dbotthepony.mc.otm.compat.jei.PlatePressRecipeCategory
import ru.dbotthepony.mc.otm.menu.matter.MatterEntanglerMenu

class MatterEntanglerScreen(menu: MatterEntanglerMenu, inventory: Inventory, title: Component) : MatteryScreen<MatterEntanglerMenu>(menu, inventory, title) {
	override fun makeMainFrame(): FramePanel<MatteryScreen<*>> {
		val frame = FramePanel(this, DEFAULT_FRAME_WIDTH, 110f, title)

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

		GridPanel.slots(this, frame, 3, 3).also {
			it.dock = Dock.LEFT
			it.dockLeft = 20f
			it.dockRight = 4f
			it.dockResize = DockResizeMode.NONE

			for (slot in menu.inputs)
				SlotPanel(this, it, slot)
		}

		ProgressGaugePanel(this, frame, menu.progress).also {
			it.dock = Dock.LEFT
			it.dockHorizontal(4f)
			it.dockResize = DockResizeMode.NONE
			it.setRecipeType { listOf(MatterEntanglerRecipeCategory.recipeType) }
		}

		SlotPanel(this, frame, menu.outputs[0]).also {
			it.dock = Dock.LEFT
			it.dockHorizontal(4f)
			it.dockResize = DockResizeMode.NONE
		}

		val strip = EditablePanel(this, frame, height = AbstractSlotPanel.SIZE)
		strip.dock = Dock.BOTTOM
		strip.dockTop = 4f
		strip.childrenOrder = -1

		SlotPanel(this, strip, menu.entanglingA).also {
			it.dock = Dock.LEFT
			it.dockLeft = 20f
		}

		SlotPanel(this, strip, menu.entanglingB).also {
			it.dock = Dock.LEFT
			it.dockLeft = 4f
		}

		SpritePanel(this, strip, ProgressGaugePanel.GAUGE_BACKGROUND).also {
			it.dock = Dock.FILL
			it.dockResize = DockResizeMode.NONE
		}

		SlotPanel(this, strip, menu.entanglingC).also {
			it.dock = Dock.RIGHT
			it.dockRight = 20f
		}

		DeviceControls(this, frame, redstoneConfig = menu.redstoneConfig, upgrades = menu.upgrades, energyConfig = menu.energyConfig, itemConfig = menu.itemConfig, experience = menu.experience)

		return frame
	}
}
