using VoiceCat.App.Forms;

namespace VoiceCat.App;

internal static class Program
{
    [STAThread]
    private static void Main()
    {
        // Surface exceptions that WinForms' default message-loop handling would otherwise
        // swallow silently (or crash with no visible cause).
        Application.ThreadException += (_, e) =>
            Console.Error.WriteLine($"[UNHANDLED ThreadException] {e.Exception}");
        AppDomain.CurrentDomain.UnhandledException += (_, e) =>
            Console.Error.WriteLine($"[UNHANDLED AppDomain exception] {e.ExceptionObject}");

        ApplicationConfiguration.Initialize();

        using var connectDialog = new ConnectDialog();
        var result = connectDialog.ShowDialog();
        if (result != DialogResult.OK || connectDialog.ConnectedClient is null)
            return;

        Application.Run(new MainForm(connectDialog.ConnectedClient, connectDialog.SelfUserId,
            connectDialog.Nickname, connectDialog.ServerName));
    }
}
