using Microsoft.UI;
using Microsoft.UI.Windowing;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Media.Imaging;
using System;
using System.Collections.ObjectModel;
using Windows.Graphics;

namespace Sonex.Client.AppWindows;

public sealed partial class AboutWindow : Window
{
    public ObservableCollection<ContributorInfo> Contributors { get; } = new()
    {

        new ContributorInfo(
            "Samuel Jendryke",
            "Software Developer and Solution Designer",
            "Responsible for the architecture, development, and technical maintenance of Sonex, provides technical support to users, consults with employees to better understand their needs, prepares proposals for new functionalities for discussion, and implements solutions in line with the project direction and real operational needs.",
            "samuel.jendryke@xenos.nl")

    };

    public string VersionText =>
        $"Version {Sonex.Client.Helpers.AppInfo.InformationalVersion.Trim()}";

    public string ContributorCountText =>
        $"{Contributors.Count} contributors";

    public AboutWindow()
    {
        InitializeComponent();

        AppWindow.Resize(new SizeInt32(600, 600));

        ExtendsContentIntoTitleBar = true;
        SetTitleBar(AppTitleBar);
        UpdateBackground();
    }

    private void UpdateBackground()
    {
        bool isDark = RootGrid.ActualTheme == ElementTheme.Dark;

        string imagePath = isDark
            ? "ms-appx:///Assets/Themes/Xenos/BackgroundDark.png"
            : "ms-appx:///Assets/Themes/Xenos/BackgroundLight.png";

        BackgroundImage.Source = new BitmapImage(new Uri(imagePath));

        BackgroundOverlay.Fill = new SolidColorBrush(
            isDark
                ? ColorHelper.FromArgb(92, 0, 0, 0)
                : ColorHelper.FromArgb(55, 255, 255, 255));
    }

    private void CloseButton_Click(object sender, RoutedEventArgs e)
    {
        Close();
    }
}

public sealed class ContributorInfo
{
    public ContributorInfo(string name, string role, string description, string email)
    {
        Name = name;
        Role = role;
        Description = description;
        Email = email;
        MailToUri = new Uri($"mailto:{email}");
    }

    public string Name { get; }
    public string Role { get; }
    public string Description { get; }
    public string Email { get; }
    public Uri MailToUri { get; }
}