using System.Windows;
using System.Windows.Controls;

namespace NexusShell.Controls;

public partial class NexusToast : Border
{
    public static readonly DependencyProperty TitleProperty =
        DependencyProperty.Register(nameof(Title), typeof(string), typeof(NexusToast),
            new PropertyMetadata(string.Empty));

    public static readonly DependencyProperty MessageProperty =
        DependencyProperty.Register(nameof(Message), typeof(string), typeof(NexusToast),
            new PropertyMetadata(string.Empty, OnMessageChanged));

    public static readonly DependencyProperty HasMessageProperty =
        DependencyProperty.Register(nameof(HasMessage), typeof(bool), typeof(NexusToast),
            new PropertyMetadata(false));

    public NexusToast()
    {
        InitializeComponent();
    }

    public string Title
    {
        get => (string)GetValue(TitleProperty);
        set => SetValue(TitleProperty, value);
    }

    public string Message
    {
        get => (string)GetValue(MessageProperty);
        set => SetValue(MessageProperty, value);
    }

    public bool HasMessage
    {
        get => (bool)GetValue(HasMessageProperty);
        private set => SetValue(HasMessageProperty, value);
    }

    private static void OnMessageChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        if (d is NexusToast toast)
        {
            toast.HasMessage = e.NewValue is string message && !string.IsNullOrWhiteSpace(message);
        }
    }
}
