package ru.dbotthepony.mc.otm.client.screen.panels.util

import com.mojang.blaze3d.vertex.PoseStack
import net.minecraft.client.gui.GuiGraphics
import net.minecraft.client.gui.screens.Screen
import ru.dbotthepony.mc.otm.client.render.StretchingRectangleElement
import ru.dbotthepony.mc.otm.client.render.WidgetLocation
import ru.dbotthepony.mc.otm.client.screen.panels.DockProperty
import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel

open class BackgroundPanel<out S : Screen>(
	screen: S,
	parent: EditablePanel<*>?,
	x: Float = 0f,
	y: Float = 0f,
	width: Float = 10f,
	height: Float = 10f,
) : EditablePanel<S>(screen, parent, x, y, width, height) {
	init {
		dockPadding = DockProperty(3f, 3f, 3f, 3f)
	}

	override fun innerRender(graphics: GuiGraphics, mouseX: Float, mouseY: Float, partialTick: Float) {
		RECTANGLE.render(graphics, width = width, height = height)
	}

	companion object {
		fun <S : Screen> padded(
			screen: S,
			parent: EditablePanel<*>?,
			x: Float = 0f,
			y: Float = 0f,
			width: Float = 10f,
			height: Float = 10f,
		) = BackgroundPanel(screen, parent, x, y, width + 6f, height + 6f)

		fun <S : Screen> paddedCenter(
			screen: S,
			parent: EditablePanel<*>?,
			x: Float = 0f,
			y: Float = 0f,
			width: Float = 10f,
			height: Float = 10f,
		) = BackgroundPanel(screen, parent, x - 3f, y - 3f, width + 6f, height + 6f)

		val RECTANGLE = StretchingRectangleElement(
			topLeft = WidgetLocation.MISC.sprite(18f, 24f, 3f, 3f),
			topRight = WidgetLocation.MISC.sprite(27f, 24f, 3f, 3f),
			bottomLeft = WidgetLocation.MISC.sprite(18f, 33f, 3f, 3f),
			bottomRight = WidgetLocation.MISC.sprite(27f, 33f, 3f, 3f),
			top = WidgetLocation.MISC.sprite(21f, 24f, 6f, 2f),
			bottom = WidgetLocation.MISC.sprite(21f, 34f, 6f, 2f),
			left = WidgetLocation.MISC.sprite(18f, 27f, 2f, 6f),
			right = WidgetLocation.MISC.sprite(28f, 27f, 2f, 6f),
			middle = WidgetLocation.MISC.sprite(30f, 12f, 6f, 6f),
			padding = DockProperty(-1f, -1f, -1f, -1f)
		)
	}
}
