<?php
declare(strict_types=1);

namespace App\Core;

final class AxiomNavigation
{
    public static function context(string $requestUri): ?array
    {
        $path = parse_url($requestUri, PHP_URL_PATH) ?: '/';
        $routes = [
            '/public/administration/axiom/kernel' => ['Kernel & Registry', '/public/administration/axiom', 'axiom.kernel.view'],
            '/public/administration/axiom' => ['AXIOM Studio', '/public/', 'dashboard.view'],
            '/public/administration/fondation' => ['Foundation', '/public/administration/axiom', 'administration.permissions.view'],
            '/public/studio/mises-a-jour' => ['Mises à jour', '/public/administration/axiom', 'updates.view'],
            '/public/studio/sauvegardes' => ['Sauvegardes', '/public/administration/axiom', 'backups.view'],
            '/public/administration/securite' => ['Permissions', '/public/administration/axiom', 'administration.permissions.view'],
            '/public/administration/axiom/referentiels' => ['Reference Engine', '/public/administration/axiom', 'parametres.disciplines.manage'],
            '/public/administration/axiom/identites' => ['Identity Engine', '/public/administration/axiom', 'clients.view'],
        ];

        foreach ($routes as $prefix => [$label, $back, $permission]) {
            if (str_starts_with($path, $prefix)) {
                return [
                    'label' => $label,
                    'back' => $back,
                    'permission' => $permission,
                    'breadcrumbs' => [
                        ['label' => 'Accueil', 'url' => '/public/'],
                        ['label' => 'AXIOM Studio', 'url' => '/public/administration/axiom'],
                        ['label' => $label, 'url' => null],
                    ],
                ];
            }
        }

        return null;
    }
}
