using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace iSTP_Core
{
    /// <summary>
    /// Test log window
    /// </summary>
    public partial class iSTP_ConsoleWnd : Form
    {
        public iSTP_ConsoleWnd()
        {
            InitializeComponent();
        }

        private void clearToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            this.Clear();
        }

        public void Clear(){
            this.TestLogTextBox.Clear();
        }

        public void WriteLine(String text, TestController.LogMsgType type) 
        {
            Color color = Color.Black;
            switch (type)
            {
                case TestController.LogMsgType.Warning:
                    color = Color.Peru;
                    break;
                case TestController.LogMsgType.Error:
                    color = Color.Red;
                    break;
            }

            if (TestLogTextBox.InvokeRequired)
            {
                TestLogTextBox.Invoke(new MethodInvoker(delegate
                {
                    int originalLength = TestLogTextBox.TextLength;
                    TestLogTextBox.AppendText(text);
                    TestLogTextBox.Select(originalLength, text.Length);
                    TestLogTextBox.SelectionColor = color;
                                                                 
                }));
            }
            else
            {
                int originalLength = TestLogTextBox.TextLength;
                TestLogTextBox.AppendText(text);
                TestLogTextBox.Select(originalLength, text.Length);
                TestLogTextBox.SelectionColor = color;
            }

        }

        private void TestLogTextBox_TextChanged(object sender, EventArgs e)
        {
            this.TestLogTextBox.ScrollToCaret();
        }

    }
}
