using Godot;

namespace ReactorMaintenance.Godot.Controls;

public partial class ConfirmDialog : PanelContainer
{
    public event Action? Confirmed;
    public event Action? Canceled;

    public void Configure(string title, string message, string confirmText = "Confirm")
    {
        foreach (var child in GetChildren())
            child.QueueFree();

        var body = new VBoxContainer();
        AddChild(body);
        body.AddChild(new Label { Text = title, HorizontalAlignment = HorizontalAlignment.Center });
        body.AddChild(new Label { Text = message, AutowrapMode = TextServer.AutowrapMode.WordSmart });

        var actions = new HBoxContainer();
        body.AddChild(actions);

        var confirm = new PrimaryButton();
        confirm.Configure(confirmText);
        confirm.Pressed += () => Confirmed?.Invoke();
        actions.AddChild(confirm);

        var cancel = new PrimaryButton();
        cancel.Configure("Cancel");
        cancel.Pressed += () => Canceled?.Invoke();
        actions.AddChild(cancel);
    }
}