using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
using ClaudeDo.Ui.Services;
using ClaudeDo.Ui.ViewModels;
using ClaudeDo.Ui.Views;
using Microsoft.Extensions.DependencyInjection;

namespace ClaudeDo.App;

public partial class App : Application
{
    public static ServiceProvider Services { get; set; } = null!;

    public override void Initialize()
    {
        AvaloniaXamlLoader.Load(this);
    }

    public override void OnFrameworkInitializationCompleted()
    {
        if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
        {
            desktop.MainWindow = new MainWindow
            {
                DataContext = Services.GetRequiredService<IslandsShellViewModel>(),
            };

            // Kick off the SignalR retry loop — reconnects indefinitely if the worker
            // is not up yet, or goes down and comes back.
            _ = Services.GetRequiredService<WorkerClient>().StartAsync();
        }

        base.OnFrameworkInitializationCompleted();
    }
}
