<?php

namespace App\Http\Controllers\Admin;

use App\Core\Controller;
use App\Core\Request;
use App\Core\Response;
use App\Services\ActivityLogger;

class ActivityLogController extends Controller
{
    public function index(Request $request, array $params = []): void
    {
        $page         = (int) ($request->query('page', 1));
        $filterAction = $request->query('action', '') ?: null;
        $filterType   = $request->query('type', '') ?: null;

        $paginated = ActivityLogger::paginated($page, 30, $filterAction, $filterType);
        $actions   = ActivityLogger::distinctActions();
        $types     = ActivityLogger::distinctResourceTypes();

        $view = $this->app->service('view');
        $html = $view->renderAdmin('activity-log/index', [
            'paginated'    => $paginated,
            'actions'      => $actions,
            'types'        => $types,
            'filterAction' => $filterAction,
            'filterType'   => $filterType,
            'pageTitle'    => __('admin.activity_log.title'),
            'auth'         => $this->auth(),
            'csrf'         => $this->csrf(),
        ]);
        Response::html($html);
    }
}
