@page "/admin/security/logs"

@using Moonlight.App.Repositories
@using Moonlight.App.Database.Entities
@using BlazorTable
@using Moonlight.Shared.Components.Navigations
@using Moonlight.App.Services

@inject Repository<SecurityLog> SecurityLogRepository
@inject SmartTranslateService SmartTranslateService

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

<AdminSecurityNavigation Index="4"/>

<div class="card">
    <div class="card-header">
        <span class="card-title">
            <TL>Security logs</TL>
        </span>
    </div>
    <div class="card-body">
        <LazyLoader Load="Load">
            <div class="table-responsive">
                <Table TableItem="SecurityLog" Items="SecurityLogs" PageSize="25" TableClass="table table-row-bordered table-row-gray-100 align-middle gs-0 gy-3" TableHeadClass="fw-bold text-muted">
                    <Column TableItem="SecurityLog" Width="80%" Title="@(SmartTranslateService.Translate("Text"))" Field="@(x => x.Text)" Filterable="true" Sortable="false"/>
                    <Column TableItem="SecurityLog" Width="20%" Title="@(SmartTranslateService.Translate("Timestamp"))" Field="@(x => x.CreatedAt)" Filterable="true" Sortable="true"/>
                    <Pager ShowPageNumber="true" ShowTotalCount="true"/>
                </Table>
            </div>
        </LazyLoader>
    </div>
</div>

@code
{
    private SecurityLog[] SecurityLogs;

    private Task Load(LazyLoader arg)
    {
        SecurityLogs = SecurityLogRepository
            .Get()
            .ToArray()
            .OrderByDescending(x => x.CreatedAt)
            .ToArray();

        return Task.CompletedTask;
    }
}