using Noctalk.UI.Components.Button;
using Noctalk.UI.Components.Label;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace Noctalk.UI.Components.Confirmation;

public static class Noctalk_confirmation
{
    public static bool Show(Window? The_owner, string The_title, string The_message)
    {
        Window dialog = new()
        {
            Title = The_title,
            Width = 480,
            Height = 170,
            WindowStartupLocation = WindowStartupLocation.CenterOwner,
            Owner = The_owner,
            ResizeMode = ResizeMode.NoResize,
            Background = UI__brush(5, 9, 18),
            Foreground = UI__brush(73, 217, 255)
        };

        Grid grid = new() { Margin = new Thickness(14) };
        grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) });
        grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });

        Noctalk_label messageLabel = new()
        {
            Text = The_message,
            Size = Noctalk_label_size.medium,
            TextWrapping = TextWrapping.Wrap,
            Foreground = UI__brush(185, 243, 255)
        };

        StackPanel buttonPanel = new()
        {
            Orientation = Orientation.Horizontal,
            HorizontalAlignment = HorizontalAlignment.Right
        };

        Noctalk_button yesButton = new() { Content = "Yes", Width = 92, Color = Noctalk_button_color.Red_R__Red_R };
        Noctalk_button cancelButton = new() { Content = "Cancel", Width = 92, Color = Noctalk_button_color.Blue_O__Blue_O };
        yesButton.Click += (_, _) => { dialog.DialogResult = true; dialog.Close(); };
        cancelButton.Click += (_, _) => { dialog.DialogResult = false; dialog.Close(); };
        buttonPanel.Children.Add(yesButton);
        buttonPanel.Children.Add(cancelButton);

        Grid.SetRow(messageLabel, 0);
        Grid.SetRow(buttonPanel, 1);
        grid.Children.Add(messageLabel);
        grid.Children.Add(buttonPanel);
        dialog.Content = grid;
        return dialog.ShowDialog() == true;
    }

    private static SolidColorBrush UI__brush(byte Red, byte Green, byte Blue)
    {
        return new SolidColorBrush(Color.FromRgb(Red, Green, Blue));
    }
}
