using System;
using System.Collections.Generic;
using System.Linq;
namespace StarterNG.Views;
///
/// The simulators offered in the settings after the folder was looked at again: a build
/// copied in while the starter runs joins the list, and what was chosen stays chosen, even
/// a file picked from elsewhere or one since removed - looking again never changes the choice.
///
public static class ExecutableList
{
/// The entries that follow "automatic", and the place of among them.
/// The simulators in the folder now, newest first.
/// The entry chosen, or null for "automatic" or nothing chosen yet.
/// Entries, and the index of the chosen one in them, -1 when is null.
public static (IReadOnlyList Entries, int Chosen) Refreshed(IReadOnlyList found, string? chosen)
{
var entries = found.ToList();
if (chosen is null)
return (entries, -1);
int at = entries.FindIndex(entry => string.Equals(entry, chosen, StringComparison.OrdinalIgnoreCase));
if (at >= 0)
return (entries, at);
entries.Add(chosen);
return (entries, entries.Count - 1);
}
}