@page "/"
@using Microsoft.AspNetCore.Authorization
@attribute [Authorize]
@rendermode InteractiveServer
@inject WishlistService Wishlists
@inject AuthenticationStateProvider AuthState

<PageTitle>WishNinja</PageTitle>

<h1>🥷 WishNinja</h1>
<p class="lead">Make wishes. Claim gifts. Keep the surprise.</p>

<div class="row g-3 mt-2">
    <div class="col-md-6">
        <div class="card h-100">
            <div class="card-body">
                <h5 class="card-title">My Wishlists</h5>
                <p class="card-text">You have @ownedCount wishlist(s).</p>
                <a class="btn btn-primary" href="wishlists">Manage my wishlists</a>
            </div>
        </div>
    </div>
    <div class="col-md-6">
        <div class="card h-100">
            <div class="card-body">
                <h5 class="card-title">Shared With Me</h5>
                <p class="card-text">@sharedCount list(s) shared with you.</p>
                <a class="btn btn-outline-primary" href="shared">Browse shared wishlists</a>
            </div>
        </div>
    </div>
</div>

@code {
    private int ownedCount;
    private int sharedCount;

    protected override async Task OnInitializedAsync()
    {
        var userId = await AuthState.GetUserIdAsync();
        if (userId is null) return;
        ownedCount = (await Wishlists.GetOwnedAsync(userId)).Count;
        sharedCount = (await Wishlists.GetSharedWithAsync(userId)).Count;
    }
}
