using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Media;

namespace AmiReel;

/// <summary>
/// Builds ContentDialogs styled to match the app's own palette and button shapes,
/// since ContentDialog's default Fluent look (accent-pill primary button, plain
/// square close button, ungrouped theme resources) does not follow our custom brushes.
/// </summary>
internal static class DialogHelper
{
    public static ContentDialog CreateStyled(XamlRoot xamlRoot, ElementTheme theme)
    {
        string themeKey = theme == ElementTheme.Dark ? "Dark" : "Light";
        ResourceDictionary themeDictionary = (ResourceDictionary)Application.Current.Resources.ThemeDictionaries[themeKey];

        return new ContentDialog
        {
            XamlRoot = xamlRoot,
            RequestedTheme = theme,
            Background = (Brush)themeDictionary["PanelBrush"],
            Foreground = (Brush)themeDictionary["TextBrush"],
            BorderBrush = (Brush)themeDictionary["HeroBorderBrush"],
            BorderThickness = new Thickness(1.5),
            CornerRadius = new CornerRadius(18),
            PrimaryButtonStyle = (Style)Application.Current.Resources["DialogPrimaryButtonStyle"],
            SecondaryButtonStyle = (Style)Application.Current.Resources["DialogCloseButtonStyle"],
            CloseButtonStyle = (Style)Application.Current.Resources["DialogCloseButtonStyle"]
        };
    }
}
