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

import mezz.jei.api.constants.RecipeTypes
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.DockProperty
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.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.widget.ProgressGaugePanel
import ru.dbotthepony.mc.otm.menu.decorative.GrillMenu

class GrillScreen(menu: GrillMenu, inventory: Inventory, title: Component) : MatteryScreen<GrillMenu>(menu, inventory, title) {
	override fun makeMainFrame(): FramePanel<MatteryScreen<*>> {
		val frame = super.makeMainFrame()!!

		val topStrip = EditablePanel(this, frame, height = AbstractSlotPanel.SIZE)
		topStrip.dock = Dock.TOP
		topStrip.dockBottom = 4f

		val middleStrip = EditablePanel(this, frame, height = AbstractSlotPanel.SIZE)
		middleStrip.dock = Dock.TOP

		for (slot in menu.inputSlots)
			SlotPanel(this, topStrip, slot).also { it.dock = Dock.LEFT }

		for (slot in menu.progress) {
			val panel = ProgressGaugePanel(this, middleStrip, slot)
			panel.type = ProgressGaugePanel.Type.FUEL
			panel.behaviorType = ProgressGaugePanel.Type.PROGRESS
			panel.dock = Dock.LEFT
			panel.dockResize = DockResizeMode.NONE
			panel.dockMargin = DockProperty(left = 2f, right = 2f)
			panel.setRecipeType { listOf(RecipeTypes.SMOKING) }
		}

		ProgressGaugePanel(this, middleStrip, menu.fuel).also {
			it.dock = Dock.LEFT
			it.dockLeft = 2f
			it.dockResize = DockResizeMode.NONE
			it.flop = true
			it.behaviorType = ProgressGaugePanel.Type.FUEL
			it.setRecipeType { listOf(RecipeTypes.FUELING) }
		}

		SlotPanel(this, middleStrip, menu.fuelSlot[0]).also {
			it.dock = Dock.LEFT
			it.dockLeft = 2f
			it.dockResize = DockResizeMode.NONE
		}

		frame.sizeToContents()

		DeviceControls(this, frame, experience = menu.experience)

		return frame
	}
}
