@page "/admin/servers/cleanup"
@using Moonlight.App.Events
@using Moonlight.App.Services.Background
@using Moonlight.Shared.Components.Navigations

@inject CleanupService CleanupService
@inject EventSystem Event

@implements IDisposable

@attribute [PermissionRequired(nameof(Permissions.AdminServerCleanup))]

<AdminServersNavigation Index="2" />

<div class="row g-5 g-xl-10 mb-5 mb-xl-10">
        <div class="col-xl-3">
            <div class="card card-flush bgi-no-repeat bgi-size-contain bgi-position-x-end h-xl-100" style="background-color: #170049;">
                <div class="card-header pt-5 mb-3">
                    <div class="d-flex flex-center rounded-circle h-80px w-80px" style="border: 1px rgba(255, 255, 255, 0.4);background-color: #7239EA">
                        <i class="text-white bx bxs-skull bx-lg"></i>
                    </div>
                </div>
                <div class="card-body d-flex align-items-end mb-3">
                    <div class="d-flex align-items-center">
                        <span class="fs-4hx text-white fw-bold me-6">@(CleanupService.ServersCleaned)</span>
                        <div class="fw-bold fs-6 text-white">
                            <span class="d-block">
                                <TL>Servers</TL>
                            </span>
                            <span>
                                <TL>stopped</TL>
                            </span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-xl-3">
            <div class="card card-flush bgi-no-repeat bgi-size-contain bgi-position-x-end h-xl-100" style="background-color: #170049;">
                <div class="card-header pt-5 mb-3">
                    <div class="d-flex flex-center rounded-circle h-80px w-80px" style="border: 1px rgba(255, 255, 255, 0.4);background-color: #7239EA">
                        <i class="text-white bx bx-transfer bx-lg"></i>
                    </div>
                </div>
                <div class="card-body d-flex align-items-end mb-3">
                    <div class="d-flex align-items-center">
                        <span class="fs-4hx text-white fw-bold me-6">@(CleanupService.CleanupsPerformed)</span>
                        <div class="fw-bold fs-6 text-white">
                            <span class="d-block">
                                <TL>Cleanups</TL>
                            </span>
                            <span>
                                <TL>executed</TL>
                            </span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-xl-3">
            <div class="card card-flush bgi-no-repeat bgi-size-contain bgi-position-x-end h-xl-100" style="background-color: #170049;">
                <div class="card-header pt-5 mb-3">
                    <div class="d-flex flex-center rounded-circle h-80px w-80px" style="border: 1px rgba(255, 255, 255, 0.4);background-color: #7239EA">
                        <i class="text-white bx bx-rocket bx-lg"></i>
                    </div>
                </div>
                <div class="card-body d-flex align-items-end mb-3">
                    <div class="d-flex align-items-center">
                        <span class="fs-4hx text-white fw-bold me-6">@(CleanupService.ServersRunning)</span>
                        <div class="fw-bold fs-6 text-white">
                            <span class="d-block">
                                <TL>Running cleanup</TL>
                            </span>
                            <span>
                                <TL>servers</TL>
                            </span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

@code
{
    protected override async Task OnInitializedAsync()
    {
        await Event.On<Object>("cleanup.updated", this, async _ =>
        {
            await InvokeAsync(StateHasChanged);
        });
    }

    public async void Dispose()
    {
        await Event.Off("cleanup.updated", this);
    }
}