using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

namespace TeslaConsole;

public class LogOutputWindow : Form
{
	private IContainer components;

	private TextBox txtOutput;

	protected override void Dispose(bool disposing)
	{
		if (disposing && components != null)
		{
			components.Dispose();
		}
		base.Dispose(disposing);
	}

	private void InitializeComponent()
	{
		this.txtOutput = new System.Windows.Forms.TextBox();
		base.SuspendLayout();
		this.txtOutput.Dock = System.Windows.Forms.DockStyle.Fill;
		this.txtOutput.Location = new System.Drawing.Point(0, 0);
		this.txtOutput.Multiline = true;
		this.txtOutput.Name = "txtOutput";
		this.txtOutput.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
		this.txtOutput.Size = new System.Drawing.Size(663, 451);
		this.txtOutput.TabIndex = 0;
		base.AutoScaleDimensions = new System.Drawing.SizeF(6f, 13f);
		base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
		base.ClientSize = new System.Drawing.Size(663, 451);
		base.Controls.Add(this.txtOutput);
		base.Name = "LogOutputWindow";
		this.Text = "Log Output Window";
		base.ResumeLayout(false);
		base.PerformLayout();
	}

	public LogOutputWindow()
	{
		InitializeComponent();
	}

	public void LogMessage(string message, params object[] args)
	{
		LogMessage(string.Format(message, args));
	}

	public void LogMessage(string message)
	{
		if (!txtOutput.IsDisposed)
		{
			int textLength = txtOutput.TextLength;
			message = $"\r\n{message}";
			if (textLength + message.Length > txtOutput.MaxLength)
			{
				txtOutput.Text = txtOutput.Text.Substring(message.Length);
			}
			txtOutput.AppendText(message);
		}
	}
}
