@using Microsoft.IdentityModel.Tokens

@typeparam TItem
@typeparam TQuery where TQuery : WatchIt.Common.Query.QueryParameters



<div class="rounded-3 panel panel-regular p-4">
    <div class="container-grid">
        <div class="row mb-4">
            <div class="col">
                <h4 class="m-0"><strong>@(Title)</strong></h4>
            </div>
        </div>
        @if (_loaded)
        {
            if (!_items.IsNullOrEmpty())
            {
                for (int i = 0; i < _items.Count; i++)
                {
                    if (i > 0)
                    {
                        <div class="row">
                            <div class="col">
                                <hr/>
                            </div>
                        </div>
                    }
                    <div class="row">
                        <div class="col">
                            <a class="text-reset text-decoration-none" href="@(string.Format(UrlIdTemplate, IdSource(_items[i])))">
                                <ListItemComponent Id="@(IdSource(_items[i]))"
                                                   Name="@(NameSource(_items[i]))"
                                                   AdditionalNameInfo="@(AdditionalNameInfoSource(_items[i]))"
                                                   Rating="@(RatingSource(_items[i]))"
                                                   PictureDownloadingTask="@(PictureDownloadingTask)"/>
                            </a>
                        </div>
                    </div>
                }
                if (!_allItemsLoaded)
                {
                    <div class="row mt-3">
                        <div class="col">
                            <div class="d-flex justify-content-center">
                                <button class="btn btn-secondary" @onclick="DownloadItems">
                                    @if (!_itemsLoading)
                                    {
                                        <span>Load more</span>
                                    }
                                    else
                                    {
                                        <span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>
                                        <span>Loading...</span>
                                    }
                                </button>
                            </div>
                        </div>
                    </div>
                }
            }
            else
            {
                <div class="row">
                    <div class="col">
                        <div class="d-flex justify-content-center">
                            No items found
                        </div>
                    </div>
                </div>
            }
        }
        else
        {
            <div class="row">
                <div class="col">
                    <LoadingComponent Color="light"/>
                </div>
            </div>
        }
    </div>
</div>