<?php

namespace App\Application\Admin;

use App\Framework\Attributes\Route;
use App\Framework\Auth\Auth;
use App\Framework\Core\PathProvider;
use App\Framework\Core\RouteCache;
use App\Framework\Discovery\Results\DiscoveryResults;
use App\Framework\Meta\MetaData;
use App\Framework\Router\Result\ViewResult;

final readonly class ShowRoutes
{
    public function __construct(
        private PathProvider $pathProvider,
        private DiscoveryResults $processedResults
    ){}

    #[Auth]
    #[Route('/admin/routes')]
    public function show(): ViewResult
    {
        $routes = $this->processedResults->get(Route::class);

        sort($routes);

        /*

        echo '<div style="font-family: monospace; font-size: 12px;">';

        echo str_repeat('-', 50) . "<br/>";

        foreach($routes as $route) {
                $path = $route['path'];
                $line = "|-- $path";

                $times = 50 - mb_strlen($line);

                $line .= str_repeat(' .', $times) . "|<br/>";

                echo $line;

        }

        echo str_repeat('-', 50) . "<br/></div>";*/

        return new ViewResult('routes',
            metaData: new MetaData('Routes', 'Routes'),
            data: [
            'name' => 'Michael',
            'title' => 'Routes',
        ],
            model: new RoutesViewModel($routes));
    }
}
