<?php

namespace App\Http\Controllers;

use App\Models\AuditLog;
use Illuminate\Http\Request;

class AdminAuditLogController extends Controller
{
    public function index(Request $request)
    {
        $action = trim((string) $request->query('action', ''));

        return view('admin.audit-logs.index', [
            'logs' => AuditLog::with('actor')
                ->when($action !== '', fn ($query) => $query->where('action', 'like', "%{$action}%"))
                ->latest()
                ->paginate(30)
                ->withQueryString(),
            'action' => $action,
        ]);
    }
}
