using LKFWSClient.WSClient;
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace LKFWSClient
{
    /// <summary>
    /// Interaction logic for LogWindow.xaml
    /// </summary>
    public partial class LogWindow : Window, ILKFClientLog
    {
        LKFClientLogLevel _lastLevel;
        LKFClientLogLevel _minimumLogLevel = LKFClientLogLevel.Info;

        public LogWindow()
        {
            InitializeComponent();
        }

        public void AppendLogLine(string text, LKFClientLogLevel logLevel)
        {

            if ((int)logLevel < (int)_minimumLogLevel)
                return;

            if (_lastLevel != logLevel)
            {
                switch (logLevel)
                {
                    case LKFClientLogLevel.Debug:
                        rtfLog.Foreground = Brushes.Gray;
                        break;
                    case LKFClientLogLevel.Error:
                        rtfLog.Foreground = Brushes.Red;
                        break;
                    case LKFClientLogLevel.Info:
                        rtfLog.Foreground = Brushes.Black;
                        break;
                    case LKFClientLogLevel.Warning:
                        rtfLog.Foreground = Brushes.Orange;
                        break;
                    }
                }

                rtfLog.AppendText(text);
                rtfLog.AppendText("\r");
        }

        private void rtfLog_Loaded(object sender, RoutedEventArgs e)
        {
            buttonClear_Click(sender, e);
        }

        private void buttonClear_Click(object sender, RoutedEventArgs e)
        {
            rtfLog.Document.Blocks.Clear();
        }
    }
}
