@extends('admin.layouts.app')
@section('title','Security & Audit')
@section('content')
<div class="page-head"><div><h1 class="page-title">Security & Audit</h1><div class="page-subtitle">Audit trail, login history, suspicious activity, 2FA and backups</div></div></div>

<div class="grid-2"><div class="card panel-tight"><h3 style="margin-top:0">2FA Settings</h3>@foreach($admins as $admin)<form method="POST" action="{{ route('admin.security.2fa',$admin) }}" style="display:flex;align-items:center;justify-content:space-between;gap:12px;margin-bottom:8px">@csrf<div>{{ $admin->name }} ({{ $admin->email }})</div><label><input type="checkbox" name="two_factor_enabled" value="1" @checked($admin->two_factor_enabled)> Enable</label><button class="btn">Save</button></form>@endforeach</div><form method="POST" action="{{ route('admin.security.snapshot') }}" class="card panel-tight grid-1">@csrf<h3 style="margin-top:0">Backup / Restore</h3><div><label>Snapshot Title</label><input name="title" required></div><div><label>Notes</label><textarea name="notes"></textarea></div><div class="form-actions"><button class="btn primary">Create Backup Snapshot</button></div></form></div>
<div class="card panel-tight table-wrap"><h3>Audit Trail</h3><table class="table"><thead><tr><th>Time</th><th>Module</th><th>Action</th><th>Ref</th><th>Admin</th></tr></thead><tbody>@forelse($auditLogs as $row)<tr><td>{{ $row->created_at }}</td><td>{{ $row->module }}</td><td>{{ $row->action }}</td><td>{{ $row->reference_no }}</td><td>{{ $row->admin_id }}</td></tr>@empty<tr><td colspan="5">No audit logs yet.</td></tr>@endforelse</tbody></table>{{ $auditLogs->links() }}</div>
<div class="card panel-tight table-wrap"><h3>Login History</h3><table class="table"><thead><tr><th>Time</th><th>Email</th><th>Status</th><th>IP</th><th>Device</th></tr></thead><tbody>@forelse($loginLogs as $row)<tr><td>{{ $row->created_at }}</td><td>{{ $row->email }}</td><td>{{ $row->status }}</td><td>{{ $row->ip_address }}</td><td>{{ \Illuminate\Support\Str::limit($row->user_agent,50) }}</td></tr>@empty<tr><td colspan="5">No login logs yet.</td></tr>@endforelse</tbody></table>{{ $loginLogs->links() }}</div>
<div class="card panel-tight table-wrap"><h3>Suspicious Activity</h3><table class="table"><thead><tr><th>Time</th><th>Module</th><th>Type</th><th>Risk</th><th>Details</th></tr></thead><tbody>@forelse($suspicious as $row)<tr><td>{{ $row->created_at }}</td><td>{{ $row->module }}</td><td>{{ $row->activity_type }}</td><td>{{ $row->risk_level }}</td><td>{{ $row->details }}</td></tr>@empty<tr><td colspan="5">No suspicious activities logged.</td></tr>@endforelse</tbody></table>{{ $suspicious->links() }}</div>
<div class="card panel-tight table-wrap"><h3>Backup Snapshots</h3><table class="table"><thead><tr><th>Title</th><th>File</th><th>Status</th><th>Action</th></tr></thead><tbody>@forelse($backups as $row)<tr><td>{{ $row->title }}</td><td>{{ $row->file_path }}</td><td>{{ $row->status }}</td><td><form method="POST" action="{{ route('admin.security.restore',$row) }}">@csrf<button class="btn">Request Restore</button></form></td></tr>@empty<tr><td colspan="4">No backups found.</td></tr>@endforelse</tbody></table>{{ $backups->links() }}</div>

@endsection
