using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;

namespace ChatController.Core
{
    public class BindableTextBlock : TextBlock
    {
        public ObservableCollection<Inline> InlineList
        {
            get => (ObservableCollection<Inline>) GetValue(InlineListProperty);
            set => SetValue(InlineListProperty, value);
        }

        public static readonly DependencyProperty InlineListProperty = DependencyProperty.Register("InlineList", typeof(ObservableCollection<Inline>), typeof(BindableTextBlock), new UIPropertyMetadata(null, OnPropertyChanged));

        public static void OnPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            if(e.NewValue == null)
            {
                return;
            }

            var textBlock = (BindableTextBlock)sender;

            textBlock.Inlines.Clear();
            textBlock.Inlines.AddRange((ObservableCollection<Inline>) e.NewValue);
        }
    }
}
