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

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.playGuiClickSound
import ru.dbotthepony.mc.otm.client.render.AbstractMatterySprite
import ru.dbotthepony.mc.otm.client.render.IGUIRenderable
import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel
import ru.dbotthepony.mc.otm.core.TextComponent
import java.util.function.IntConsumer

@Suppress("PropertyName")
abstract class RectangleButtonPanel<out S : Screen>(
	screen: S,
	parent: EditablePanel<*>?,
	x: Float = 0f,
	y: Float = 0f,
	width: Float,
	height: Float,
	var onPress: IntConsumer? = null,
) : AbstractButtonPanel<S>(screen, parent, x, y, width, height) {
	abstract val PRESSED: IGUIRenderable
	abstract val HOVERED: IGUIRenderable
	abstract val IDLE: IGUIRenderable
	abstract val DISABLED: IGUIRenderable

	override fun onClick(mouseButton: Int) {
		onPress?.accept(mouseButton)
	}

	protected fun renderSquareButton(graphics: GuiGraphics, mouseX: Float, mouseY: Float, partialTick: Float) {
		if (isDisabled) {
			DISABLED.render(graphics, 0f, 0f, width, height)
		} else if (isPressed) {
			PRESSED.render(graphics, 0f, 0f, width, height)
		} else if (isHovered) {
			HOVERED.render(graphics, 0f, 0f, width, height)
		} else {
			IDLE.render(graphics, 0f, 0f, width, height)
		}
	}

	override fun innerRender(graphics: GuiGraphics, mouseX: Float, mouseY: Float, partialTick: Float) {
		renderSquareButton(graphics, mouseX, mouseY, partialTick)
	}
}
