@page "/admin"
@using Moonlight.App.Repositories.Servers
@using Moonlight.App.Repositories
@using Moonlight.App.Repositories.Domains
@using Moonlight.App.Database.Entities

@inject ServerRepository ServerRepository
@inject UserRepository UserRepository
@inject Repository<WebSpace> WebSpaceRepository
@inject DomainRepository DomainRepository

<OnlyAdmin>
    <LazyLoader Load="Load">
        <div class="row mb-5">
            <div class="col-12 col-lg-6 col-xl">
                <a class="mt-4 card" href="/admin/servers">
                    <div class="card-body">
                        <div class="row align-items-center gx-0">
                            <div class="col">
                                <h6 class="text-uppercase text-muted mb-2">
                                    <TL>Servers</TL>
                                </h6>
                                <span class="h2 mb-0">
                                    @(ServerCount)
                                </span>
                            </div>
                            <div class="col-auto">
                                <span class="h2 text-muted mb-0">
                                    <i class="text-primary bx bx-server bx-lg"></i>
                                </span>
                            </div>
                        </div>
                    </div>
                </a>
            </div>
            <div class="col-12 col-lg-6 col-xl">
                <a class="mt-4 card" href="/admin/webspaces">
                    <div class="card-body">
                        <div class="row align-items-center gx-0">
                            <div class="col">
                                <h6 class="text-uppercase text-muted mb-2">
                                    <TL>Webspaces</TL>
                                </h6>
                                <span class="h2 mb-0">
                                    @(WebSpaceCount)
                                </span>
                            </div>
                            <div class="col-auto">
                                <span class="h2 text-muted mb-0">
                                    <i class="text-primary bx bx-globe bx-lg"></i>
                                </span>
                            </div>
                        </div>
                    </div>
                </a>
            </div>
            <div class="col-12 col-lg-6 col-xl">
                <a class="mt-4 card" href="/admin/domains">
                    <div class="card-body">
                        <div class="row align-items-center gx-0">
                            <div class="col">
                                <h6 class="text-uppercase text-muted mb-2">
                                    <TL>Domains</TL>
                                </h6>
                                <span class="h2 mb-0">
                                    @(DomainCount)
                                </span>
                            </div>
                            <div class="col-auto">
                                <span class="h2 text-muted mb-">
                                    <i class="text-primary bx bx-purchase-tag bx-lg"></i>
                                </span>
                            </div>
                        </div>
                    </div>
                </a>
            </div>
            <div class="col-12 col-lg-6 col-xl">
                <a class="mt-4 card" href="/admin/users">
                    <div class="card-body">
                        <div class="row align-items-center gx-0">
                            <div class="col">
                                <h6 class="text-uppercase text-muted mb-2">
                                    <TL>Users</TL>
                                </h6>
                                <span class="h2 mb-0">
                                    @(UserCount)
                                </span>
                            </div>
                            <div class="col-auto">
                                <span class="h2 text-muted mb-">
                                    <i class="text-primary bx bx-user bx-lg"></i>
                                </span>
                            </div>
                        </div>
                    </div>
                </a>
            </div>
        </div>
    </LazyLoader>
</OnlyAdmin>

@code
{
    private int ServerCount = 0;
    private int UserCount = 0;
    private int DomainCount = 0;
    private int WebSpaceCount = 0;

    private Task Load(LazyLoader lazyLoader)
    {
        ServerCount = ServerRepository.Get().Count();
        UserCount = UserRepository.Get().Count();
        DomainCount = DomainRepository.Get().Count();
        WebSpaceCount = WebSpaceRepository.Get().Count();

        return Task.CompletedTask;
    }
}