using Godot;
using ReactorMaintenance.Godot.Controls;

namespace ReactorMaintenance.Godot.Screens;

public abstract partial class ScreenBase : Control
{
    protected VBoxContainer CreatePage(string title)
    {
        foreach (var child in GetChildren())
            child.QueueFree();

        SetAnchorsPreset(LayoutPreset.FullRect);

        var margin = new MarginContainer {
            AnchorRight = 1,
            AnchorBottom = 1
        };
        margin.AddThemeConstantOverride("margin_left", 48);
        margin.AddThemeConstantOverride("margin_top", 36);
        margin.AddThemeConstantOverride("margin_right", 48);
        margin.AddThemeConstantOverride("margin_bottom", 36);
        AddChild(margin);

        var body = new VBoxContainer {
            SizeFlagsHorizontal = SizeFlags.ExpandFill,
            SizeFlagsVertical = SizeFlags.ExpandFill
        };
        margin.AddChild(body);

        var titleLabel = new Label {
            Text = title,
            HorizontalAlignment = HorizontalAlignment.Center
        };
        titleLabel.AddThemeFontSizeOverride("font_size", 32);
        body.AddChild(titleLabel);

        return body;
    }

    protected static PrimaryButton CreateButton(string text, Action pressed, string tooltip = "", bool disabled = false)
    {
        var button = new PrimaryButton();
        button.Configure(text, tooltip, disabled);
        button.Pressed += pressed;
        return button;
    }

    protected static Label CreateBodyText(string text)
    {
        return new() {
            Text = text,
            AutowrapMode = TextServer.AutowrapMode.WordSmart,
            HorizontalAlignment = HorizontalAlignment.Center,
            SizeFlagsHorizontal = SizeFlags.ExpandFill
        };
    }
}