@extends('layouts.panel')

@section('title', 'Activity Logs')

@section('content')
    <section class="card">
        <div class="page-header">
            <p class="eyebrow">Audit Trail</p>
            <h1>Everything important is logged</h1>
            <p class="muted">Authentication, website changes, backups, and agent sync activity land here for accountability.</p>
        </div>

        <form method="get" class="form-grid" style="grid-template-columns: 1fr 2fr auto;">
            <label>
                <span>Category</span>
                <select class="field" name="category">
                    <option value="">All categories</option>
                    @foreach (['auth', 'website', 'backup', 'agent', 'settings', 'database'] as $category)
                        <option value="{{ $category }}" @selected(($filters['category'] ?? '') === $category)>{{ str($category)->headline() }}</option>
                    @endforeach
                </select>
            </label>

            <label>
                <span>Search</span>
                <input class="field" type="search" name="search" value="{{ $filters['search'] ?? '' }}" placeholder="Action, description, website">
            </label>

            <div style="display: flex; align-items: end;">
                <button class="button secondary" type="submit">Filter</button>
            </div>
        </form>
    </section>

    <section class="card">
        <div class="table-wrap">
            <table>
                <thead>
                    <tr>
                        <th>User</th>
                        <th>Action</th>
                        <th>Website</th>
                        <th>IP</th>
                        <th>Timestamp</th>
                    </tr>
                </thead>
                <tbody>
                    @forelse ($logs as $log)
                        <tr>
                            <td>{{ $log->user?->name ?? 'System' }}</td>
                            <td>
                                <strong>{{ str($log->action)->headline() }}</strong>
                                <div class="muted">{{ $log->description }}</div>
                            </td>
                            <td>{{ $log->website?->name ?? 'System' }}</td>
                            <td>{{ $log->ip_address ?? 'N/A' }}</td>
                            <td>{{ $log->occurred_at->format('M d, Y H:i') }}</td>
                        </tr>
                    @empty
                        <tr><td colspan="5" class="muted">No activity found.</td></tr>
                    @endforelse
                </tbody>
            </table>
        </div>

        {{ $logs->links() }}
    </section>
@endsection
