using ClaudeDo.Ui.ViewModels;
using Xunit;

namespace ClaudeDo.Ui.Tests;

public class ConnectionPromptGateTests
{
    [Fact]
    public void Shows_once_when_offline()
    {
        var vm = new IslandsShellViewModel();
        Assert.True(vm.DecideShowConnectionPrompt(isOffline: true));
        Assert.False(vm.DecideShowConnectionPrompt(isOffline: true)); // not a second time
    }

    [Fact]
    public void Does_not_show_when_connected_before_grace()
    {
        var vm = new IslandsShellViewModel();
        Assert.False(vm.DecideShowConnectionPrompt(isOffline: false));
    }

    // The footer pill binds OpenWorkerConnectionHelpCommand, and the dialog says "WORKER NOT
    // REACHABLE" — so it must stay closed while the worker is connected, and stay reachable
    // while it is not (including the endless "connecting" retry state).
    [Theory]
    [InlineData(true, false)]
    [InlineData(false, true)]
    public void Connection_help_is_gated_on_connected(bool isConnected, bool canOpen)
        => Assert.Equal(canOpen, IslandsShellViewModel.DecideCanOpenConnectionHelp(isConnected));

    [Fact]
    public void Connection_help_command_enabled_without_worker()
    {
        var vm = new IslandsShellViewModel();
        Assert.True(vm.OpenWorkerConnectionHelpCommand.CanExecute(null));
    }
}
