using Godot;

namespace ReactorMaintenance.Godot.Controls;

public partial class OutcomeOverlay : PanelContainer
{
    public override void _Ready()
    {
        CustomMinimumSize = new(420, 220);
        AddChild(m_Body);
        m_Body.AddChild(m_Title);
        m_Body.AddChild(m_Message);
        m_Body.AddChild(m_Actions);
        m_Title.HorizontalAlignment = HorizontalAlignment.Center;
        m_Title.AddThemeFontSizeOverride("font_size", 26);
        m_Message.AutowrapMode = TextServer.AutowrapMode.WordSmart;
        m_Message.HorizontalAlignment = HorizontalAlignment.Center;
    }

    protected void Configure(string title, string message, IReadOnlyList<(string Text, Action Pressed)> actions)
    {
        m_Title.Text = title;
        m_Message.Text = message;

        foreach (var child in m_Actions.GetChildren())
            child.QueueFree();

        foreach (var action in actions)
        {
            var button = new PrimaryButton();
            button.Configure(action.Text);
            button.Pressed += action.Pressed;
            m_Actions.AddChild(button);
        }
    }

    private readonly HBoxContainer m_Actions = new();
    private readonly VBoxContainer m_Body = new();
    private readonly Label m_Message = new();
    private readonly Label m_Title = new();
}