@inject ConversationService conversationService
@using Common.Dtos.Group
@using HushianWebApp.Service
@if (groups.Where(w => w.Available).Count() > 0)
{
    @Content

}


@code {
    [Parameter]
    public List<Read_GroupDto> groups { get; set; }
    [Parameter] public EventCallback<int> OnMultipleOfThree { get; set; }
    [Parameter] public int CompanyID { get; set; }
    async Task onClickSelectedGroup(int ID)
    {
        await OnMultipleOfThree.InvokeAsync(ID);
    }
    RenderFragment Content { get; set; }
    List<kv> ints = new();
    protected override async Task OnParametersSetAsync()
    {
        foreach (var g in groups.Where(w => w.Available))
        {
            ints.Add(new()
            {
                k=g.ID,
                    v = await conversationService.GetCountQueueCompany(CompanyID, g.ID)
            });
        }

        Content =@<div class="text-end mb-3">
        <span class="badge bg-success p-2">گروه های فعال</span><br />

        @foreach (var g in groups.Where(w=>w.Available))
    {
        <button class="btn btn-outline-secondary btn-sm mt-2"
                @onclick="async()=>await onClickSelectedGroup(g.ID)" style="margin-left:5px">
            @g.Name  (@ints.FirstOrDefault(f=>f.k==g.ID)?.v)
        </button>

    }
    </div>
    ;
        await base.OnParametersSetAsync();
    }
    public class kv
    {
        public int k { get; set; }
        public int v { get; set; }
    }
}
