@extends('layouts.admin', ['heading' => 'Activity Logs', 'subheading' => 'Admin audit trail'])

@section('content')
    <form method="GET" class="mb-4 flex flex-wrap gap-2">
        <input name="q" value="{{ $search }}" placeholder="Search action / subject" class="w-full rounded border p-2 md:max-w-sm" />
        <button class="rounded bg-slate-900 px-4 py-2 text-white">Search</button>
    </form>

    <div class="admin-card p-5">
        <div class="overflow-x-auto">
            <table class="min-w-full text-sm">
                <thead class="bg-slate-100 text-left">
                    <tr>
                        <th class="p-3">Admin</th>
                        <th class="p-3">Action</th>
                        <th class="p-3">Subject</th>
                        <th class="p-3">IP</th>
                        <th class="p-3">At</th>
                    </tr>
                </thead>
                <tbody>
                    @forelse($logs as $log)
                        <tr class="border-t">
                            <td class="p-3">{{ $log->adminUser?->name ?? 'System' }}</td>
                            <td class="p-3">{{ $log->action }}</td>
                            <td class="p-3">{{ $log->subject_type }} #{{ $log->subject_id }}</td>
                            <td class="p-3">{{ $log->ip_address }}</td>
                            <td class="p-3">{{ optional($log->created_at)->format('Y-m-d H:i') }}</td>
                        </tr>
                    @empty
                        <tr><td colspan="5" class="p-4 text-center text-slate-500">No activity logs.</td></tr>
                    @endforelse
                </tbody>
            </table>
        </div>

        <div class="mt-4">{{ $logs->links() }}</div>
    </div>
@endsection
