using System.Windows;
using PSLauncher.Core.Localization;
using PSLauncher.Models;

namespace PSLauncher.App.Views;

public partial class UpdateAvailableDialog : Window
{
    public UpdateAvailableDialog(VersionManifest version, string releaseNotesMarkdown)
    {
        InitializeComponent();

        var sizeText = version.Download.SizeBytes > 0
            ? Strings.FormatSize(version.Download.SizeBytes)
            : Strings.SizeUnknown;

        DataContext = new
        {
            Title = Strings.UpdateAvailableHeading(version.Version),
            Subtitle = Strings.UpdateAvailableSubtitle(Strings.FormatLongDate(version.ReleasedAt), sizeText),
            ReleaseNotesDocument = MarkdownTheming.BuildThemedDocument(releaseNotesMarkdown)
        };
    }

    public bool DownloadRequested { get; private set; }

    private void OnDownload(object sender, RoutedEventArgs e)
    {
        DownloadRequested = true;
        DialogResult = true;
        Close();
    }

    private void OnLater(object sender, RoutedEventArgs e)
    {
        DownloadRequested = false;
        DialogResult = false;
        Close();
    }
}
