@inherits FnzComponentBase
@typeparam TValue

@code {
    [Parameter] public IReadOnlyCollection<TValue> DataSource { get; set; }
    [Parameter] public string ContainerCssClass { get; set; } = "btn-group";
    [Parameter] public string ItemCssClass { get; set; } = "btn btn-outline-primary";
    [Parameter] public Func<TValue, string> TextFormat { get; set; } = x => x?.ToString();
    [Parameter] public TValue Value { get; set; }
    [Parameter] public EventCallback<TValue> ValueChanged { get; set; } = EventCallback<TValue>.Empty;
}

<div id="@ElementId" class="@ContainerCssClass">
    @foreach (var item in DataSource ?? Array.Empty<TValue>())
    {
        <FnzRadio TValue="TValue" Name="@ElementId" CssClass="@ItemCssClass"
                  Text="@TextFormat(item)" Value="item"
                  Checked="@(Comparer<TValue>.Default.Compare(Value,item)==0)" Click="ItemClicked"></FnzRadio>
    }
</div>

@code
{
    private async Task ItemClicked(FnzRadio<TValue> source)
    {
        if (Comparer<TValue>.Default.Compare(Value, source.Value) != 0)
        {
            Value = source.Value;
            await ValueChanged.InvokeAsync(Value);
        }
    }
}
