using AIStudio.Settings; using Microsoft.AspNetCore.Components; namespace AIStudio.Components; /// /// Configuration component for selecting many values from a list. /// /// The type of the value to select. public partial class ConfigurationMultiSelect : ConfigurationBase { /// /// The data to select from. /// [Parameter] public IEnumerable> Data { get; set; } = []; /// /// The selected values. /// [Parameter] public Func> SelectedValues { get; set; } = () => []; /// /// An action that is called when the selection changes. /// [Parameter] public Action> SelectionUpdate { get; set; } = _ => { }; private async Task OptionChanged(IEnumerable? updatedValues) { if(updatedValues is null) this.SelectionUpdate([]); else this.SelectionUpdate(updatedValues.Where(n => n is not null).ToHashSet()!); await this.SettingsManager.StoreSettings(); await this.InformAboutChange(); } private static string GetClass => $"{MARGIN_CLASS} rounded-lg"; private string GetMultiSelectionText(List? selectedValues) { if(selectedValues is null || selectedValues.Count == 0) return T("No preview features selected."); if(selectedValues.Count == 1) return T("You have selected 1 preview feature."); return string.Format(T("You have selected {0} preview features."), selectedValues.Count); } }