<?php

namespace Mtc\Plugins\BlockManager\Http\Controllers;

use Illuminate\Http\JsonResponse;
use Illuminate\Routing\Controller;
use Mtc\Plugins\BlockManager\Services\ElementCatalogueService;

/**
 * Read-only JSON endpoint for the element catalogue.
 *
 * Extends Laravel's base routing controller directly (not App\Http\Controllers\Controller)
 * because the project's base controller boots Twig globals and an admin-session lookup
 * (`$_SESSION['adminId']`) that aren't relevant — and aren't initialised — for a stateless
 * JSON read.
 */
class ElementCatalogueController extends Controller
{
    public function __construct(private ElementCatalogueService $catalogue)
    {
    }

    public function index(): JsonResponse
    {
        return response()->json(['data' => $this->catalogue->list()]);
    }
}
