@extends('layouts.app')
@section('title', 'Auditoria')
@section('content')
    <div class="page-heading"><div><span class="eyebrow">CONTROLO E RASTREABILIDADE</span><h1>Auditoria do sistema</h1><p>Registo cronológico das alterações e eventos relevantes, sem registar simples consultas.</p></div><span class="phase-pill">{{ number_format($audits->total(),0,',','.') }} evento(s)</span></div>
    <form class="panel filter-bar" method="GET"><label class="field"><span>Evento</span><select name="event"><option value="">Todos</option>@foreach($events as $event)<option value="{{ $event }}" @selected(request('event') === $event)>{{ str_replace('_',' ',ucfirst($event)) }}</option>@endforeach</select></label><label class="field"><span>Utilizador</span><select name="actor_id"><option value="">Todos</option>@foreach($users as $user)<option value="{{ $user->id }}" @selected(request('actor_id') == $user->id)>{{ $user->name }}</option>@endforeach</select></label><label class="field"><span>De</span><input type="date" name="date_from" value="{{ request('date_from') }}"></label><label class="field"><span>Até</span><input type="date" name="date_to" value="{{ request('date_to') }}"></label><button class="filter-button" type="submit">Aplicar filtros</button></form>
    <section class="panel audit-table"><div class="table-wrap"><table class="management-table"><thead><tr><th>Data/hora</th><th>Evento</th><th>Descrição</th><th>Responsável</th><th>Filial</th><th>Origem</th></tr></thead><tbody>@forelse($audits as $audit)<tr><td><strong>{{ $audit->created_at?->format('d/m/Y') }}</strong><small>{{ $audit->created_at?->format('H:i:s') }}</small></td><td><code>{{ $audit->event }}</code></td><td>{{ $audit->description }}</td><td>{{ $audit->actor?->name ?? 'Sistema' }}</td><td>{{ $audit->branch?->name ?? 'Consolidado/Sistema' }}</td><td>{{ $audit->ip_address ?: '—' }}</td></tr>@empty<tr><td colspan="6"><div class="empty-state">Não foram encontrados eventos com estes filtros.</div></td></tr>@endforelse</tbody></table></div><div class="pagination-bar"><span>Página {{ $audits->currentPage() }} de {{ $audits->lastPage() }}</span><div>@if($audits->previousPageUrl())<a href="{{ $audits->previousPageUrl() }}">← Anterior</a>@endif @if($audits->nextPageUrl())<a href="{{ $audits->nextPageUrl() }}">Seguinte →</a>@endif</div></div></section>
@endsection
