@using ZB.MOM.WW.OtOpcUa.Admin.Services
@using ZB.MOM.WW.OtOpcUa.Configuration.Entities
@inject AuditLogService AuditSvc

<h4>Recent audit log</h4>

@if (_entries is null) { <p>Loading…</p> }
else if (_entries.Count == 0) { <p class="text-muted">No audit entries for this cluster yet.</p> }
else
{
    <table class="table table-sm">
        <thead><tr><th>When</th><th>Principal</th><th>Event</th><th>Node</th><th>Generation</th><th>Details</th></tr></thead>
        <tbody>
        @foreach (var a in _entries)
        {
            <tr>
                <td>@a.Timestamp.ToString("u")</td>
                <td>@a.Principal</td>
                <td><code>@a.EventType</code></td>
                <td>@a.NodeId</td>
                <td>@a.GenerationId</td>
                <td><small class="text-muted">@a.DetailsJson</small></td>
            </tr>
        }
        </tbody>
    </table>
}

@code {
    [Parameter] public string ClusterId { get; set; } = string.Empty;
    private List<ConfigAuditLog>? _entries;

    protected override async Task OnParametersSetAsync() =>
        _entries = await AuditSvc.ListRecentAsync(ClusterId, limit: 100, CancellationToken.None);
}
