using FluentIcons.Common;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;

namespace Sonex.Client.Controls;

public class NavigationViewSymbolItem : NavigationViewItem
{
    public FluentIcons.Common.Symbol SymbolIcon
    {
        get => (FluentIcons.Common.Symbol)GetValue(SymbolIconProperty);
        set => SetValue(SymbolIconProperty, value);
    }

    public static readonly DependencyProperty SymbolIconProperty =
        DependencyProperty.Register(
            nameof(SymbolIcon),
            typeof(FluentIcons.Common.Symbol),
            typeof(NavigationViewSymbolItem),
            new PropertyMetadata(default(FluentIcons.Common.Symbol), OnIconPropertyChanged));

    public IconVariant IconVariant
    {
        get => (IconVariant)GetValue(IconVariantProperty);
        set => SetValue(IconVariantProperty, value);
    }

    public static readonly DependencyProperty IconVariantProperty =
        DependencyProperty.Register(
            nameof(IconVariant),
            typeof(IconVariant),
            typeof(NavigationViewSymbolItem),
            new PropertyMetadata(IconVariant.Regular, OnIconPropertyChanged));

    private static void OnIconPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        if (d is NavigationViewSymbolItem item)
        {
            item.Icon = new FluentIcons.WinUI.SymbolIcon
            {
                Symbol = item.SymbolIcon,
                IconVariant = item.IconVariant
            };
        }
    }
}