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

namespace ChatController.Utilities
{
    public class WpfUtils
    {
        public static void ScrollToBottomOfListBox(ListBox listBox)
        {
            if (VisualTreeHelper.GetChildrenCount(listBox) > 0)
            {
                var border = (Border)VisualTreeHelper.GetChild(listBox, 0);
                var scrollViewer = (ScrollViewer)VisualTreeHelper.GetChild(border, 0);

                scrollViewer?.ScrollToBottom();
            }
        }

        public static ScrollViewer GetListBoxScrollViewer(ListBox listBox)
        {
            if (VisualTreeHelper.GetChildrenCount(listBox) > 0)
            {
                var border = (Border)VisualTreeHelper.GetChild(listBox, 0);
                var scrollViewer = (ScrollViewer)VisualTreeHelper.GetChild(border, 0);

                return scrollViewer;
            }

            return null;
        }
    }
}
