@extends('layouts.app')

@section('title', 'Audit Log Aktivitas')
@section('page-title', 'Audit Log Aktivitas Sistem')
@section('page-subtitle', 'Jejak audit seluruh aktivitas user, perubahan data, login, logout, dan aksi penting.')

@section('content')
<div class="card shadow-sm border-0">
    <div class="card-header bg-white py-3 border-bottom d-flex justify-content-between align-items-center">
        <h5 class="card-title mb-0 fw-bold"><i class="bi bi-shield-check text-primary me-2"></i> Rekam Jejak Audit (Audit Trail)</h5>
        <span class="badge bg-light-primary text-primary">Total: {{ $logs->total() }} Log</span>
    </div>
    <div class="card-body p-0">
        <div class="table-responsive">
            <table class="table table-hover align-middle mb-0">
                <thead class="bg-light">
                    <tr>
                        <th class="ps-4">Waktu</th>
                        <th>User</th>
                        <th>Aksi</th>
                        <th>Deskripsi Aktivitas</th>
                        <th>IP Address</th>
                        <th class="pe-4">User Agent</th>
                    </tr>
                </thead>
                <tbody>
                    @forelse($logs as $log)
                        <tr>
                            <td class="ps-4 text-xs">
                                <strong>{{ $log->created_at->format('d/m/Y') }}</strong>
                                <br><span class="text-muted">{{ $log->created_at->format('H:i:s') }}</span>
                            </td>
                            <td>
                                <strong>{{ $log->user?->name ?? 'Sistem' }}</strong>
                                <br><small class="text-muted">{{ $log->user?->email ?? '-' }}</small>
                            </td>
                            <td>
                                <span class="badge bg-light-primary text-primary">{{ $log->action }}</span>
                            </td>
                            <td>{{ $log->description ?? '-' }}</td>
                            <td><code>{{ $log->ip_address ?? '-' }}</code></td>
                            <td class="pe-4 text-xs text-muted">
                                <span class="d-inline-block text-truncate" style="max-width: 200px;" title="{{ $log->user_agent }}">
                                    {{ $log->user_agent ?? '-' }}
                                </span>
                            </td>
                        </tr>
                    @empty
                        <tr>
                            <td colspan="6" class="text-center py-5 text-muted">
                                Belum ada catatan aktivitas audit log.
                            </td>
                        </tr>
                    @endforelse
                </tbody>
            </table>
        </div>

        @if($logs->hasPages())
            <div class="p-3 border-top d-flex justify-content-end">
                {{ $logs->links('pagination::bootstrap-5') }}
            </div>
        @endif
    </div>
</div>
@endsection
