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

import net.minecraft.client.gui.screens.Screen
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 kotlin.math.max

fun <B : EditablePanel<S>, L : EditablePanel<S>, S : Screen> makeButtonLabel(
	screen: S,
	parent: EditablePanel<*>?,
	button: B,
	label: L,
	x: Float = 0f,
	y: Float = 0f,
): Triple<B, L, EditablePanel<S>> {
	val canvas = EditablePanel(screen, parent, x, y)

	with(canvas) {
		width = button.width + label.width + 2f
		height = max(button.height, label.height)

		button.parent = this
		label.parent = this

		button.childrenOrder = 0
		label.childrenOrder = 1

		button.dockMargin = DockProperty.EMPTY
		label.dockMargin = DockProperty(left = 2f)

		label.dock = Dock.FILL
		label.dockResize = DockResizeMode.WIDTH

		button.dock = Dock.LEFT
		button.dockResize = DockResizeMode.NONE
	}

	return Triple(button, label, canvas)
}
