@extends('layouts.app')
@section('title','Audit Log')
@section('content')
@php
    $filters = [];
    if(request()->filled('action')) $filters[] = ['label'=>'Action','value'=>request('action'),'removeUrl'=>route('admin.audit.index',request()->except(['action','page']))];
@endphp

<x-ui.page-toolbar title="Audit Log" description="Review security-sensitive and operational activity recorded across accessible branches." :breadcrumbs="[['label'=>'Dashboard','url'=>route('dashboard')],['label'=>'Administration'],['label'=>'Audit Log']]" />

<x-ui.table-toolbar table-id="audit-table" search-name="action" search-placeholder="Search actions…" :columns="[
    'date'=>'Date','user'=>'User','branch'=>'Branch','action'=>'Action','record'=>'Record'
]" export-filename="audit-log.csv" />
<x-ui.applied-filter-chips :filters="$filters" :clear-url="route('admin.audit.index')" />

<div class="mf-table-frame">
<table id="audit-table" class="mf-table" data-standard-table>
<thead><tr><th data-table-column="date">Date</th><th data-table-column="user">User</th><th data-table-column="branch">Branch</th><th data-table-column="action">Action</th><th data-table-column="record">Record</th></tr></thead>
<tbody>
@forelse($logs as $log)
<tr>
    <td data-table-column="date">{{ $log->created_at?->format('d M Y H:i') }}</td>
    <td data-table-column="user">{{ $log->user?->name ?: 'System' }}</td>
    <td data-table-column="branch">{{ $log->branch?->name ?: '—' }}</td>
    <td data-table-column="action"><span class="font-medium">{{ $log->action }}</span></td>
    <td data-table-column="record">{{ $log->auditable_type ? class_basename($log->auditable_type) : '—' }}@if($log->auditable_id) #{{ $log->auditable_id }}@endif</td>
</tr>
@empty<tr><td colspan="5" class="text-center text-muted-foreground">No audit records found.</td></tr>@endforelse
</tbody>
</table>
</div>
<div class="mt-4">{{ $logs->links() }}</div>
@endsection
